<html class="_ok_app_hidden translated-ltr" lang="en" style="width: 100%; margin-left: 0px;">
<head>
    <title>教程：使用Thymeleaf</title>
    <meta charset="utf-8">
    <meta content="pandoc" name="generator">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <meta content="telephone=no" name="format-detection">

    <link href="https://fonts.googleapis.com/css?family=Ubuntu:400,400italic,700,700italic" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic,700italic" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/css/normalize.css}">
    <link rel="stylesheet" th:href="@{/css/thymeleaf.css}">
    <link rel="stylesheet" th:href="@{/css/thymeleaf-tutorials.css}">
    <link media="screen" rel="stylesheet" th:href="@{/css/thymeleaf-tutorials-screen.css}">
    <link media="print" rel="stylesheet" th:href="@{/css/thymeleaf-tutorials-print.css}">

    <!-- <script src="../../scripts/dumbqueryselector.js}" defer=""></script>
    <script src="../../scripts/prism.js}" defer="" data-manual=""></script>
    <script src="../../scripts/thymeleaf-tutorials.js}" defer=""></script>-->
    <meta content="style-src * 'unsafe-inline' 'self' blob: data: file:" http-equiv="Content-Security-Policy">
    <style>
        @-moz-keyframes nodeInserted{from{opacity:0.99;}to{opacity:1;}}@-webkit-keyframes nodeInserted{from{opacity:0.99;}to{opacity:1;}}@-o-keyframes nodeInserted{from{opacity:0.99;}to{opacity:1;}}@keyframes nodeInserted{from{opacity:0.99;}to{opacity:1;}}embed,object{animation-duration:.001s;-ms-animation-duration:.001s;-moz-animation-duration:.001s;-webkit-animation-duration:.001s;-o-animation-duration:.001s;animation-name:nodeInserted;-ms-animation-name:nodeInserted;-moz-animation-name:nodeInserted;-webkit-animation-name:nodeInserted;-o-animation-name:nodeInserted;}



    </style>
    <link charset="UTF-8" href="https://translate.googleapis.com/translate_static/css/translateelement.css}"
          rel="stylesheet"
          type="text/css">
</head>
<body class="tutorial" style="position: static;">

<div class="toc-wrapper toolbar-container">
    <div class="toolbar-menu">
        <div class="toolbar-menu-location" id="toolbar-location"></div>
        <button class="toolbar-menu-button" id="site-menu-button" type="button"><font><font>文件内容</font></font></button>
    </div>
    <nav id="toc">
        <ul class="level1">
            <li><a href="#introducing-thymeleaf"><font><font>1介绍Thymeleaf</font></font></a>
                <ul class="level2">
                    <li><a href="#what-is-thymeleaf"><font><font>1.1什么是Thymeleaf</font></font></a></li>
                    <li>
                        <a href="#what-kind-of-templates-can-thymeleaf-process"><font><font>1.2什么样的模板可以让Thymeleaf进行？</font></font></a>
                    </li>
                    <li><a href="#dialects-the-standard-dialect"><font><font>1.3方言：标准方言</font></font></a></li>
                </ul>
            </li>
            <li><a href="#the-good-thymes-virtual-grocery"><font><font>2好的Thymes虚拟杂货店</font></font></a>
                <ul class="level2">
                    <li><a href="#a-website-for-a-grocery"><font><font>2.1杂货店的网站</font></font></a></li>
                    <li>
                        <a href="#creating-and-configuring-the-template-engine"><font><font>2.2创建和配置模板引擎</font></font></a>
                        <ul class="level3">
                            <li><a href="#the-template-resolver"><font><font>模板解析器</font></font></a></li>
                            <li><a href="#the-template-engine"><font><font>模板引擎</font></font></a></li>
                        </ul>
                    </li>
                </ul>
            </li>
            <li><a href="#using-texts"><font><font>3使用文本</font></font></a>
                <ul class="level2">
                    <li><a href="#a-multi-language-welcome"><font><font>3.1多语言欢迎</font></font></a>
                        <ul class="level3">
                            <li>
                                <a href="#using-thtext-and-externalizing-text"><font><font>使用th：文本和外部化文本</font></font></a>
                            </li>
                            <li><a href="#contexts"><font><font>上下文</font></font></a></li>
                            <li><a href="#executing-the-template-engine"><font><font>执行模板引擎</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#more-on-texts-and-variables"><font><font>3.2更多文本和变量</font></font></a>
                        <ul class="level3">
                            <li><a href="#unescaped-text"><font><font>非转义文本</font></font></a></li>
                            <li><a href="#using-and-displaying-variables"><font><font>使用和显示变量</font></font></a></li>
                        </ul>
                    </li>
                </ul>
            </li>
            <li><a href="#standard-expression-syntax"><font><font>4标准表达式语法</font></font></a>
                <ul class="level2">
                    <li><a href="#messages"><font><font>4.1消息</font></font></a></li>
                    <li><a href="#variables"><font><font>4.2变量</font></font></a>
                        <ul class="level3">
                            <li><a href="#expression-basic-objects"><font><font>表达式基本对象</font></font></a></li>
                            <li><a href="#expression-utility-objects"><font><font>表达式实用程序对象</font></font></a></li>
                            <li>
                                <a href="#reformatting-dates-in-our-home-page"><font><font>在我们的主页重新格式化日期</font></font></a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a href="#expressions-on-selections-asterisk-syntax"><font><font>4.3选择表达式（星号语法）</font></font></a>
                    </li>
                    <li><a href="#link-urls"><font><font>4.4链接URL</font></font></a>
                        <ul class="level3">
                            <li><a href="#a-menu-for-our-home-page"><font><font>我们的主页菜单</font></font></a></li>
                            <li><a href="#server-root-relative-urls"><font><font>服务器根相对URL</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#fragments"><font><font>4.5片段</font></font></a></li>
                    <li><a href="#literals"><font><font>4.6文字</font></font></a>
                        <ul class="level3">
                            <li><a href="#text-literals"><font><font>文字文字</font></font></a></li>
                            <li><a href="#number-literals"><font><font>数字字面值</font></font></a></li>
                            <li><a href="#boolean-literals"><font><font>布尔文字</font></font></a></li>
                            <li><a href="#the-null-literal"><font><font>无效文字</font></font></a></li>
                            <li><a href="#literal-tokens"><font><font>文字代币</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#appending-texts"><font><font>4.7附加文本</font></font></a></li>
                    <li><a href="#literal-substitutions"><font><font>4.8字面替代</font></font></a></li>
                    <li><a href="#arithmetic-operations"><font><font>4.9算术运算</font></font></a></li>
                    <li><a href="#comparators-and-equality"><font><font>4.10比较与平等</font></font></a></li>
                    <li><a href="#conditional-expressions"><font><font>4.11条件表达式</font></font></a></li>
                    <li><a href="#default-expressions-elvis-operator"><font><font>4.12默认表达式（Elvis
                        operator）</font></font></a></li>
                    <li><a href="#the-no-operation-token"><font><font>4.13无操作令牌</font></font></a></li>
                    <li><a href="#data-conversion-formatting"><font><font>4.15数据转换/格式化</font></font></a></li>
                    <li><a href="#preprocessing"><font><font>4.14预处理</font></font></a></li>
                </ul>
            </li>
            <li><a href="#setting-attribute-values"><font><font>5设置属性值</font></font></a>
                <ul class="level2">
                    <li><a href="#setting-the-value-of-any-attribute"><font><font>5.1设置任何属性的值</font></font></a></li>
                    <li><a href="#setting-value-to-specific-attributes"><font><font>5.2将值设置为特定属性</font></font></a></li>
                    <li><a href="#setting-more-than-one-value-at-a-time"><font><font>5.3一次设置多个值</font></font></a></li>
                    <li><a href="#appending-and-prepending"><font><font>5.4附加和前缀</font></font></a></li>
                    <li><a href="#fixed-value-boolean-attributes"><font><font>5.5固定值布尔属性</font></font></a></li>
                    <li><a href="#setting-the-value-of-any-attribute-default-attribute-processor"><font><font>5.6设置任意属性的值（默认属性处理器）</font></font></a>
                    </li>
                    <li><a href="#support-for-html5-friendly-attribute-and-element-names"><font><font>5.7支持HTML5友好的属性和元素名称</font></font></a>
                    </li>
                </ul>
            </li>
            <li><a href="#iteration"><font><font>6迭代</font></font></a>
                <ul class="level2">
                    <li><a href="#iteration-basics"><font><font>6.1迭代基础</font></font></a>
                        <ul class="level3">
                            <li><a href="#using-theach"><font><font>使用th：each</font></font></a></li>
                            <li><a href="#iterable-values"><font><font>可迭代的值</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#keeping-iteration-status"><font><font>6.2保持迭代状态</font></font></a></li>
                    <li>
                        <a href="#optimizing-through-lazy-retrieval-of-data"><font><font>6.3通过懒惰检索数据进行优化</font></font></a>
                    </li>
                </ul>
            </li>
            <li><a href="#conditional-evaluation"><font><font>7条件评估</font></font></a>
                <ul class="level2">
                    <li><a href="#simple-conditionals-if-and-unless"><font><font>7.1简单条件：“如果”和“除非”</font></font></a>
                    </li>
                    <li><a href="#switch-statements"><font><font>7.2切换语句</font></font></a></li>
                </ul>
            </li>
            <li><a href="#template-layout"><font><font>8模板布局</font></font></a>
                <ul class="level2">
                    <li><a href="#including-template-fragments"><font><font>8.1包括模板片段</font></font></a>
                        <ul class="level3">
                            <li><a href="#defining-and-referencing-fragments"><font><font>定义和引用片段</font></font></a></li>
                            <li><a href="#fragment-specification-syntax"><font><font>片段规范语法</font></font></a></li>
                            <li>
                                <a href="#referencing-fragments-without-thfragment"><font><font>没有引用片段 </font></font><code>th:fragment</code></a>
                            </li>
                            <li><a href="#difference-between-thinsert-and-threplace-and-thinclude"><font></font><code>th:insert</code><font><font>和</font></font><code>th:replace</code><font><font>（和</font></font><code>th:include</code><font><font>）</font><font>之间的差异</font></font></a>
                            </li>
                        </ul>
                    </li>
                    <li><a href="#parameterizable-fragment-signatures"><font><font>8.2可参数化的片段签名</font></font></a>
                        <ul class="level3">
                            <li>
                                <a href="#fragment-local-variables-without-fragment-arguments"><font><font>不带片段参数的片段局部变量</font></font></a>
                            </li>
                            <li><a href="#thassert-for-in-template-assertions"><font><font>th：assert for in-template
                                assertions</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#flexible-layouts-beyond-mere-fragment-insertion"><font><font>8.3灵活的布局：不仅仅是片段插入</font></font></a>
                        <ul class="level3">
                            <li><a href="#using-the-empty-fragment"><font><font>使用空的片段</font></font></a></li>
                            <li><a href="#using-the-no-operation-token"><font><font>使用无操作令牌</font></font></a></li>
                            <li>
                                <a href="#advanced-conditional-insertion-of-fragments"><font><font>高级条件插入片段</font></font></a>
                            </li>
                        </ul>
                    </li>
                    <li><a href="#removing-template-fragments"><font><font>8.4删除模板片段</font></font></a></li>
                </ul>
            </li>
            <li><a href="#local-variables"><font><font>9个本地变量</font></font></a></li>
            <li><a href="#attribute-precedence"><font><font>10属性优先</font></font></a></li>
            <li><a href="#comments-and-blocks"><font><font>11评论和块</font></font></a>
                <ul class="level2">
                    <li><a href="#standard-htmlxml-comments"><font><font>11.1。</font><font>标准HTML / XML注释</font></font></a>
                    </li>
                    <li>
                        <a href="#thymeleaf-parser-level-comment-blocks"><font><font>11.2。</font><font>Thymeleaf解析器级注释块</font></font></a>
                    </li>
                    <li><a href="#thymeleaf-prototype-only-comment-blocks"><font><font>11.3。</font><font>Thymeleaf原型只有评论块</font></font></a>
                    </li>
                    <li>
                        <a href="#synthetic-thblock-tag"><font><font>11.4。</font><font>合成</font></font><code>th:block</code><font><font>标签</font></font></a>
                    </li>
                </ul>
            </li>
            <li><a href="#inlining"><font><font>12内联</font></font></a>
                <ul class="level2">
                    <li><a href="#expression-inlining"><font><font>12.1表达式内联</font></font></a>
                        <ul class="level3">
                            <li><a href="#inlining-vs-natural-templates"><font><font>内联与自然模板</font></font></a></li>
                            <li><a href="#disabling-inlining"><font><font>禁用内联</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#text-inlining"><font><font>12.2文本内联</font></font></a></li>
                    <li><a href="#javascript-inlining"><font><font>12.3 JavaScript内联</font></font></a>
                        <ul class="level3">
                            <li><a href="#javascript-natural-templates"><font><font>JavaScript自然模板</font></font></a>
                            </li>
                            <li><a href="#advanced-inlined-evaluation-and-javascript-serialization"><font><font>高级内联评估和JavaScript序列化</font></font></a>
                            </li>
                        </ul>
                    </li>
                    <li><a href="#css-inlining"><font><font>12.4 CSS内联</font></font></a>
                        <ul class="level3">
                            <li><a href="#advanced-features-css-natural-templates-etc."><font><font>高级功能：CSS自然模板等</font></font></a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
            <li><a href="#textual-template-modes"><font><font>13文本模板模式</font></font></a>
                <ul class="level2">
                    <li><a href="#textual-syntax"><font><font>13.1文本语法</font></font></a>
                        <ul class="level3">
                            <li><a href="#escaped-element-attributes"><font><font>转义的元素属性</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#extensibility"><font><font>13.2可扩展性</font></font></a></li>
                    <li><a href="#textual-prototype-only-comment-blocks-adding-code"><font><font>13.3文本原型注释块：添加代码</font></font></a>
                    </li>
                    <li>
                        <a href="#textual-parser-level-comment-blocks-removing-code"><font><font>13.4文本解析器级注释块：删除代码</font></font></a>
                    </li>
                    <li>
                        <a href="#natural-javascript-and-css-templates"><font><font>13.5自然的JavaScript和CSS模板</font></font></a>
                    </li>
                </ul>
            </li>
            <li><a href="#some-more-pages-for-our-grocery"><font><font>14我们的杂货店还有一些页面</font></font></a>
                <ul class="level2">
                    <li><a href="#order-list"><font><font>14.1订单</font></font></a></li>
                    <li><a href="#order-details"><font><font>14.2订单明细</font></font></a></li>
                </ul>
            </li>
            <li><a href="#more-on-configuration"><font><font>15更多配置</font></font></a>
                <ul class="level2">
                    <li><a href="#template-resolvers"><font><font>15.1模板解析器</font></font></a>
                        <ul class="level3">
                            <li><a href="#chaining-template-resolvers"><font><font>链接模板解决方案</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#message-resolvers"><font><font>15.2消息解析器</font></font></a>
                        <ul class="level3">
                            <li><a href="#standard-message-resolver"><font><font>标准消息解析器</font></font></a></li>
                            <li><a href="#configuring-message-resolvers"><font><font>配置消息解析器</font></font></a></li>
                        </ul>
                    </li>
                    <li><a href="#conversion-services"><font><font>15.3转换服务</font></font></a></li>
                    <li><a href="#logging"><font><font>15.4记录</font></font></a></li>
                </ul>
            </li>
            <li><a href="#template-cache"><font><font>16模板缓存</font></font></a></li>
            <li><a href="#decoupled-template-logic"><font><font>17去耦模板逻辑</font></font></a>
                <ul class="level2">
                    <li><a href="#decoupled-logic-the-concept"><font><font>17.1解耦逻辑：概念</font></font></a></li>
                    <li><a href="#configuring-decoupled-templates"><font><font>17.2配置去耦模板</font></font></a>
                        <ul class="level3">
                            <li><a href="#enabling-decoupled-templates"><font><font>启用解耦模板</font></font></a></li>
                            <li><a href="#mixing-coupled-and-decoupled-logic"><font><font>混合耦合和去耦逻辑</font></font></a>
                            </li>
                        </ul>
                    </li>
                    <li><a href="#the-thref-attribute"><font><font>17.3 th：ref属性</font></font></a></li>
                    <li><a href="#performance-impact-of-decoupled-templates"><font><font>17.4去耦模板的性能影响</font></font></a>
                    </li>
                    <li><a href="#resolution-of-decoupled-logic"><font><font>17.5解耦逻辑的分辨率</font></font></a></li>
                </ul>
            </li>
            <li><a href="#appendix-a-expression-basic-objects"><font><font>18附录A：表达式基本对象</font></font></a>
                <ul class="level2">
                    <li><a href="#base-objects"><font><font>基础对象</font></font></a></li>
                    <li><a href="#web-context-namespaces-for-requestsession-attributes-etc."><font><font>用于请求/会话属性等的Web上下文名称空间</font></font></a>
                    </li>
                    <li><a href="#web-context-objects"><font><font>Web上下文对象</font></font></a></li>
                </ul>
            </li>
            <li><a href="#appendix-b-expression-utility-objects"><font><font>19附录B：表达式实用程序对象</font></font></a>
                <ul class="level2">
                    <li><a href="#execution-info"><font><font>执行信息</font></font></a></li>
                    <li><a href="#messages-1"><font><font>消息</font></font></a></li>
                    <li><a href="#urisurls"><font><font>URI / URL</font></font></a></li>
                    <li><a href="#conversions"><font><font>转换</font></font></a></li>
                    <li><a href="#dates"><font><font>日期</font></font></a></li>
                    <li><a href="#calendars"><font><font>日历</font></font></a></li>
                    <li><a href="#numbers"><font><font>数字</font></font></a></li>
                    <li><a href="#strings"><font><font>弦</font></font></a></li>
                    <li><a href="#objects"><font><font>对象</font></font></a></li>
                    <li><a href="#booleans"><font><font>布尔值</font></font></a></li>
                    <li><a href="#arrays"><font><font>数组</font></font></a></li>
                    <li><a href="#lists"><font><font>列表</font></font></a></li>
                    <li><a href="#sets"><font><font>集合</font></font></a></li>
                    <li><a href="#maps"><font><font>地图</font></font></a></li>
                    <li><a href="#aggregates"><font><font>聚集</font></font></a></li>
                    <li><a href="#ids"><font><font>ID</font></font></a></li>
                </ul>
            </li>
            <li><a href="#appendix-c-markup-selector-syntax"><font><font>20附录C：标记选择器语法</font></font></a>
                <ul class="level2">
                    <li><a href="#multivalued-class-matching"><font><font>多值类匹配</font></font></a></li>
                </ul>
            </li>
        </ul>
    </nav>
</div>

<div class="content-wrapper">

    <div class="title-container">
        <header class="hero-header fluid-block">
            <div class="hero-header-text">
                <h1 class="hero-header-title"><font><font>Thymeleaf</font></font></h1>
            </div>
            <div class="hero-header-image">
                <img alt="Thymeleaf标志" class="hero-header-logo" src="/image/thymeleaf.png">
            </div>
        </header>

        <div class="tutorial-info fluid-block">
            <h1 class="tutorial-title" id="tutorial-title"><font><font>教程：使用Thymeleaf</font></font></h1>
            <div class="tutorial-metadata">
                <div id="tutorial-version">
                    <span class="tutorial-metadata-label"><font><font>文件版本：</font></font></span><font><font> 20170418 -
                    2017年4月18日
                </font></font></div>
                <div id="project-version">
                    <span class="tutorial-metadata-label"><font><font>项目版本：</font></font></span><font><font>
                    3.0.5.RELEASE
                </font></font></div>
                <div id="project-website">
                    <span class="tutorial-metadata-label"><font><font>项目网站：</font></font></span>
                    <font><a href="http://www.thymeleaf.org"><font>http </font></a><span
                            class="tutorial-metadata-label"><font>：</font></span></font><a
                        href="http://www.thymeleaf.org"><font><font>//www.thymeleaf.org</font></font></a>
                </div>
            </div>
        </div>
    </div>

    <div class="fluid-block" id="content">
        <section class="level1" id="introducing-thymeleaf">
            <h1><font><font>1介绍Thymeleaf</font></font></h1>
            <section class="level2" id="what-is-thymeleaf">
                <h2><font><font>1.1什么是Thymeleaf</font></font></h2>
                <p><font><font>Thymeleaf是面向Web和独立环境的现代服务器端Java模板引擎，能够处理HTML，XML，JavaScript，CSS甚至纯文本。</font></font></p>
                <p>
                    <font><font>Thymeleaf的主要目标是提供一个优雅和高度可维护的创建模板的方式。</font><font>为了实现这一点，它建立在</font></font><em><font><font>自然</font></font></em><font><font>模板</font><font>的概念上，</font><font>将其逻辑注入到模板文件中，不会影响模板被用作设计原型。</font><font>这改善了设计的沟通，弥合了设计和开发团队之间的差距。</font></font>
                </p>
                <p><font><font>Thymeleaf也从一开始就设计了Web标准 -
                    特别是</font></font><strong><font><font>HTML5</font></font></strong><font><font> -
                    允许您创建完全验证的模板，如果这是您需要的。</font></font></p>
            </section>
            <section class="level2" id="what-kind-of-templates-can-thymeleaf-process">
                <h2><font><font>1.2什么样的模板可以让Thymeleaf进行？</font></font></h2>
                <p>
                    <font><font>开箱即用的Thymeleaf可让您处理六种模板，每种</font></font><strong><font><font>模板</font></font></strong><font><font>称为</font><strong><font>模板模式</font></strong><font>：</font></font>
                </p>
                <ul>
                    <li><font><font>HTML</font></font></li>
                    <li><font><font>XML</font></font></li>
                    <li><font><font>文本</font></font></li>
                    <li><font><font>JAVASCRIPT</font></font></li>
                    <li><font><font>CSS</font></font></li>
                    <li><font><font>生的</font></font></li>
                </ul>
                <p>
                    <font><font>有两种</font></font><em><font><font>标记</font></font></em><font><font>模板模式（</font></font><code>HTML</code><font><font>和</font></font><code>XML</code><font><font>），三个</font></font><em><font><font>文本</font></font></em><font><font>模板模式（</font></font><code>TEXT</code><font><font>，</font></font><code>JAVASCRIPT</code><font><font>和</font></font><code>CSS</code><font><font>）和</font></font><em><font><font>无操作</font></font></em><font><font>模板模式（</font></font><code>RAW</code><font><font>）。</font></font>
                </p>
                <p><font><font>该</font></font><strong><code>HTML</code></strong><font><font>模板模式将允许任何类型的HTML的输入，包括HTML5，HTML4和XHTML。</font><font>将不执行验证或形式良好检查，并且模板代码/结构将在产出中尽可能的最大程度地得到尊重。</font></font>
                </p>
                <p><font><font>该</font></font><strong><code>XML</code></strong><font><font>模板模式将允许XML输入。</font><font>在这种情况下，代码预期形式良好
                    - 没有未关闭的标签，没有引用属性等，如果找到良好的违规行为，解析器将抛出异常。</font><font>请注意，不会</font></font><em><font><font>执行验证</font></font></em><font><font>（针对DTD或XML架构）。</font></font>
                </p>
                <p><font></font><strong><code>TEXT</code></strong><font><font>模板模式将允许对非标记性质</font><font>的</font><font>模板使用特殊语法。</font><font>此类模板的示例可能是文本电子邮件或模板文档。</font><font>请注意，HTML或XML模板也可以处理</font></font><code>TEXT</code><font><font>，在这种情况下，它们将不会被解析为标记，并且每个标签DOCTYPE，注释等将被视为纯文本。</font></font>
                </p>
                <p><font><font>该</font></font><strong><code>JAVASCRIPT</code></strong><font><font>模板模式将允许在Thymeleaf应用程序的JavaScript文件的处理。</font><font>这意味着能够使用JavaScript文件中的模型数据与HTML文件中可以完成的方式相同，但可以使用特定于JavaScript的集成，例如专门的转义或</font></font><em><font><font>自然脚本</font></font></em><font><font>。</font><font>该</font></font><code>JAVASCRIPT</code><font><font>模板模式被认为是一种</font></font><em><font><font>文本</font></font></em><font><font>模式，因此使用相同的特殊语法的</font></font><code>TEXT</code><font><font>模板模式。</font></font>
                </p>
                <p>
                    <font><font>该</font></font><strong><code>CSS</code></strong><font><font>模板模式将允许参与Thymeleaf应用CSS文件的处理。</font><font>与</font></font><code>JAVASCRIPT</code><font><font>模式</font><font>类似</font><font>，</font></font><code>CSS</code><font><font>模板模式也是</font></font><em><font><font>文本</font></font></em><font><font>模式，并使用</font></font><code>TEXT</code><font><font>模板模式下</font><font>的特殊处理语法</font><font>。</font></font>
                </p>
                <p><font><font>该</font></font><strong><code>RAW</code></strong><font><font>模板模式将根本不处理模板。</font><font>它用于将未经修改的资源（文件，URL响应等）插入正在处理的模板中。</font><font>例如，HTML格式的外部不受控制的资源可以包含在应用程序模板中，安全地知道这些资源可能包含的任何Thymeleaf代码将不会被执行。</font></font>
                </p>
            </section>
            <section class="level2" id="dialects-the-standard-dialect">
                <h2><font><font>1.3方言：标准方言</font></font></h2>
                <p>
                    <font><font>Thymeleaf是一个非常可扩展的模板引擎（实际上它可以称为</font></font><em><font><font>模板引擎框架</font></font></em><font><font>），允许您定义和自定义您的模板将被处理到一个很好的细节水平。</font></font>
                </p>
                <p><font><font>将一些逻辑应用于标记工件（标签，某些文本，注释或只有占位符，如果模板不是标记）的一个</font></font><em><font><font>对象</font></font></em><font><font>被称为</font><em><font>处理器</font></em><font>，并且这些处理器的集合以及一些额外的工件是什么一个</font></font><strong><font><font>方言</font></font></strong><font><font>通常包括。</font><font>开箱即用，Thymeleaf的核心库提供了一种称为</font></font><strong><font><font>标准方言的方言</font></font></strong><font><font>，这对大多数用户来说应该是足够的。</font></font>
                </p>
                <blockquote>
                    <p><font><font>请注意，方言实际上可能没有处理器，并且完全由其他类型的工件组成，但处理器绝对是最常见的用例。</font></font></p>
                </blockquote>
                <p><em><font><font>本教程涵盖标准方言</font></font></em><font><font>。</font><font>您将在以下页面中了解的每个属性和语法功能都由此方言定义，即使没有明确提及。</font></font>
                </p>
                <p><font><font>当然，如果用户希望在利用库的高级功能的同时定义自己的处理逻辑，用户也可以创建自己的方言（甚至扩展标准的方言）。</font><font>也可以将Thymeleaf配置为一次使用几种方言。</font></font>
                </p>
                <blockquote>
                    <p><font><font>官方的ThymeleafSpring3和ThymeleafSpring4的整合包都定义了一种称为“春季标准方言”的方言，与“标准方言”大致相同，但是对于Spring框架中的某些功能（例如，
                        ，通过使用Spring Expression Language或SpringEL而不是OGNL）。</font><font>所以如果你是一个Spring
                        MVC用户，你不会浪费你的时间，因为你在这里学到的所有东西都将在你的Spring应用程序中使用。</font></font></p>
                </blockquote>
                <p>
                    <font><font>标准方言的</font></font><em><font><font>大多数处理器</font></font></em><font><font>是</font><em><font>属性处理器</font></em><font>。</font><font>这样，即使在处理之前，浏览器也可以正确地显示HTML模板文件，因为它们将简单地忽略其他属性。</font><font>例如，虽然使用标记库的JSP可能包含不能像浏览器那样直接显示的代码片断：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span><span
                        class="token namespace">form:</span>inputText</span> <span
                        class="token attr-name">name</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>userName<span
                        class="token punctuation">"</span></span> <span class="token attr-name">value</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${user.name}<span
                        class="token punctuation">"</span></span> <span
                        class="token punctuation">/&gt;</span></span></code></pre>
                <p><font><font>... Thymeleaf标准方言将允许我们实现与以下功能相同的功能：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
                        class="token attr-name">type</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>text<span
                        class="token punctuation">"</span></span> <span class="token attr-name">name</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>userName<span class="token punctuation">"</span></span> <span
                        class="token attr-name">value</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>James Carrot<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>value</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>${user.name}<span
                        class="token punctuation">"</span></span> <span
                        class="token punctuation">/&gt;</span></span></code></pre>
                <p><font><font>浏览器不仅可以正确显示这些信息，而且还可以（可选地）在浏览器中静态打开原型时显示的值（可选地）指定一个值属性（在这种情况下为“James
                    Carrot”），将由</font></font><code>${user.name}</code><font><font>模板处理过程中的评估结果代替。</font></font></p>
                <p>
                    <font><font>这有助于您的设计师和开发人员处理相同的模板文件，并减少将静态原型转换为工作模板文件所需的工作量。</font><font>这样做的功能是称为</font></font><em><font><font>自然模板</font></font></em><font><font>的功能</font><font>。</font></font>
                </p>
            </section>
        </section>
        <section class="level1" id="the-good-thymes-virtual-grocery">
            <h1><font><font>2好的Thymes虚拟杂货店</font></font></h1>
            <p><font><font>本指南和本指南的未来章节中显示的示例的源代码可以在</font></font><a
                    href="https://github.com/thymeleaf/thymeleafexamples-gtvg"><font><font>Good Thymes Virtual Grocery
                GitHub存储库中找到</font></font></a><font><font>。</font></font></p>
            <section class="level2" id="a-website-for-a-grocery">
                <h2><font><font>2.1杂货店的网站</font></font></h2>
                <p><font><font>为了更好地解释使用Thymeleaf处理模板所涉及的概念，本教程将使用您可以从项目网站下载的演示应用程序。</font></font></p>
                <p><font><font>这个应用程序是一个想象的虚拟杂货店的网站，并将为我们提供许多场景来展示Thymeleaf的许多功能。</font></font></p>
                <p>
                    <font><font>为了开始，我们需要一套简单的模型实体，用于我们的应用程序：</font><font>通过创建</font></font><code>Products</code><font><font>出售</font><font>。</font><font>我们也将管理</font><font>这些</font><font>：</font></font><code>Customers</code><font></font><code>Orders</code><font></font><code>Comments</code><font></font><code>Products</code><font></font>
                </p>
                <figure>
                    <img alt="示例应用模型" src="images/usingthymeleaf/gtvg-model.png">
                    <figcaption><font><font>示例应用模型</font></font></figcaption>
                </figure>
                <p>
                    <font><font>我们的应用程序也将有一个非常简单的服务层，由包含</font></font><code>Service</code><font><font>以下方法</font><font>的</font><font>对象</font><font>组成</font><font>：</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java"><span
                        class="token keyword">public</span> <span class="token keyword">class</span> <span
                        class="token class-name">ProductService</span> <span
                        class="token punctuation">{</span><font></font>
<font></font>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span
                            class="token punctuation">.</span><font></font>
<font></font>
    <span class="token keyword">public</span> List<span class="token operator">&lt;</span>Product<span
                            class="token operator">&gt;</span> <span class="token function">findAll</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span> <span
                            class="token punctuation">{</span>
        <span class="token keyword">return</span> ProductRepository<span class="token punctuation">.</span><span
                            class="token function">getInstance</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">.</span><span
                            class="token function">findAll</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><font></font>
<font></font>
    <span class="token keyword">public</span> Product <span class="token function">findById</span><span
                            class="token punctuation">(</span>Integer id<span class="token punctuation">)</span> <span
                            class="token punctuation">{</span>
        <span class="token keyword">return</span> ProductRepository<span class="token punctuation">.</span><span
                            class="token function">getInstance</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">.</span><span
                            class="token function">findById</span><span class="token punctuation">(</span>id<span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><font></font>
    <font></font>
<span class="token punctuation">}</span></code></pre>
                <p><font><font>在Web层，我们的应用程序将有一个过滤器，将根据请求URL将执行委托给启用Thymeleaf的命令：</font></font></p>
                <pre class="  language-java"><code class="  language-java"><span
                        class="token keyword">private</span> <span class="token keyword">boolean</span> <span
                        class="token function">process</span><span class="token punctuation">(</span>HttpServletRequest request<span
                        class="token punctuation">,</span> HttpServletResponse response<span
                        class="token punctuation">)</span>
        <span class="token keyword">throws</span> ServletException <span class="token punctuation">{</span><font></font>
    <font></font>
    <span class="token keyword">try</span> <span class="token punctuation">{</span><font></font>
<font></font>
        <span class="token comment"
              spellcheck="true">// This prevents triggering engine executions for resource URLs</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>request<span
                            class="token punctuation">.</span><span class="token function">getRequestURI</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">.</span><span class="token function">startsWith</span><span
                            class="token punctuation">(</span><span class="token string">"/css"</span><span
                            class="token punctuation">)</span> <span class="token operator">||</span>
                request<span class="token punctuation">.</span><span class="token function">getRequestURI</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">.</span><span class="token function">startsWith</span><span
                            class="token punctuation">(</span><span class="token string">"/images"</span><span
                            class="token punctuation">)</span> <span class="token operator">||</span>
                request<span class="token punctuation">.</span><span class="token function">getRequestURI</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">.</span><span class="token function">startsWith</span><span
                            class="token punctuation">(</span><span class="token string">"/favicon"</span><span
                            class="token punctuation">)</span><span class="token punctuation">)</span> <span
                            class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token boolean">false</span><span
                            class="token punctuation">;</span>
        <span class="token punctuation">}</span><font></font>
<font></font>
        <font></font>
        <span class="token comment" spellcheck="true">/*
         * Query controller/URL mapping and obtain the controller
         * that will process the request. If no controller is available,
         * return false and let other filters/servlets process the request.
         */</span>
        IGTVGController controller <span class="token operator">=</span> <span class="token keyword">this</span><span
                            class="token punctuation">.</span>application<span class="token punctuation">.</span><span
                            class="token function">resolveControllerForRequest</span><span
                            class="token punctuation">(</span>request<span class="token punctuation">)</span><span
                            class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>controller <span
                            class="token operator">==</span> null<span class="token punctuation">)</span> <span
                            class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token boolean">false</span><span
                            class="token punctuation">;</span>
        <span class="token punctuation">}</span><font></font>
<font></font>
        <span class="token comment" spellcheck="true">/*
         * Obtain the TemplateEngine instance.
         */</span>
        ITemplateEngine templateEngine <span class="token operator">=</span> <span
                            class="token keyword">this</span><span class="token punctuation">.</span>application<span
                            class="token punctuation">.</span><span class="token function">getTemplateEngine</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span><font></font>
<font></font>
        <span class="token comment" spellcheck="true">/*
         * Write the response headers
         */</span>
        response<span class="token punctuation">.</span><span class="token function">setContentType</span><span
                            class="token punctuation">(</span><span
                            class="token string">"text/html;charset=UTF-8"</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">setHeader</span><span
                            class="token punctuation">(</span><span class="token string">"Pragma"</span><span
                            class="token punctuation">,</span> <span class="token string">"no-cache"</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">setHeader</span><span
                            class="token punctuation">(</span><span class="token string">"Cache-Control"</span><span
                            class="token punctuation">,</span> <span class="token string">"no-cache"</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">setDateHeader</span><span
                            class="token punctuation">(</span><span class="token string">"Expires"</span><span
                            class="token punctuation">,</span> <span class="token number">0</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
<font></font>
        <span class="token comment" spellcheck="true">/*
         * Execute the controller and process view template,
         * writing the results to the response writer.
         */</span>
        controller<span class="token punctuation">.</span><span class="token function">process</span><span
                            class="token punctuation">(</span>
                request<span class="token punctuation">,</span> response<span class="token punctuation">,</span> <span
                            class="token keyword">this</span><span class="token punctuation">.</span>servletContext<span
                            class="token punctuation">,</span> templateEngine<span
                            class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
        <font></font>
        <span class="token keyword">return</span> <span class="token boolean">true</span><span
                            class="token punctuation">;</span><font></font>
        <font></font>
    <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span
                            class="token punctuation">(</span><span class="token class-name">Exception</span> e<span
                            class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            response<span class="token punctuation">.</span><span class="token function">sendError</span><span
                            class="token punctuation">(</span>HttpServletResponse<span
                            class="token punctuation">.</span>SC_INTERNAL_SERVER_ERROR<span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span
                            class="token punctuation">(</span><span class="token class-name">final</span> IOException ignored<span
                            class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment" spellcheck="true">// Just ignore this</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">ServletException</span><span
                            class="token punctuation">(</span>e<span class="token punctuation">)</span><span
                            class="token punctuation">;</span>
    <span class="token punctuation">}</span><font></font>
    <font></font>
<span class="token punctuation">}</span></code></pre>
                <p><font><font>这是我们的</font></font><code>IGTVGController</code><font><font>界面：</font></font></p>
                <pre class="  language-java"><code class="  language-java"><span
                        class="token keyword">public</span> <span class="token keyword">interface</span> <span
                        class="token class-name">IGTVGController</span> <span
                        class="token punctuation">{</span><font></font>
<font></font>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">process</span><span
                            class="token punctuation">(</span>
            HttpServletRequest request<span class="token punctuation">,</span> HttpServletResponse response<span
                            class="token punctuation">,</span>
            ServletContext servletContext<span class="token punctuation">,</span> ITemplateEngine templateEngine<span
                            class="token punctuation">)</span><span class="token punctuation">;</span>    <font></font>
    <font></font>
<span class="token punctuation">}</span></code></pre>
                <p>
                    <font><font>我们现在要做的就是创建接口的</font></font><code>IGTVGController</code><font><font>实现，从服务中检索数据，并使用</font></font><code>ITemplateEngine</code><font><font>对象</font><font>处理模板</font><font>。</font></font>
                </p>
                <p><font><font>最后，它将如下所示：</font></font></p>
                <figure>
                    <img alt="示例应用程序主页" src="images/usingthymeleaf/gtvg-view.png">
                    <figcaption><font><font>示例应用程序主页</font></font></figcaption>
                </figure>
                <p><font><font>但首先让我们看看该模板引擎是如何初始化的。</font></font></p>
            </section>
            <section class="level2" id="creating-and-configuring-the-template-engine">
                <h2><font><font>2.2创建和配置模板引擎</font></font></h2>
                <p>
                    <font><font>该</font></font><em><font><font>过程（...）</font></font></em><font><font>在我们的过滤方法包含这一行：</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java">ITemplateEngine templateEngine <span
                        class="token operator">=</span> <span class="token keyword">this</span><span
                        class="token punctuation">.</span>application<span class="token punctuation">.</span><span
                        class="token function">getTemplateEngine</span><span class="token punctuation">(</span><span
                        class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                <p><font><font>这意味着</font></font><em><font><font>GTVGApplication</font></font></em><font><font>类负责创建和配置Thymeleaf应用程序中最重要的对象之一：</font></font><code>TemplateEngine</code><font><font>实例（接口的</font></font><code>ITemplateEngine</code><font><font>实现）。</font></font>
                </p>
                <p>
                    <font><font>我们的</font></font><code>org.thymeleaf.TemplateEngine</code><font><font>对象是这样初始化的：</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java"><span
                        class="token keyword">public</span> <span class="token keyword">class</span> <span
                        class="token class-name">GTVGApplication</span> <span
                        class="token punctuation">{</span><font></font>
  <font></font>
    <font></font>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span
                            class="token punctuation">.</span>
    <span class="token keyword">private</span> <span
                            class="token keyword">static</span> TemplateEngine templateEngine<span
                            class="token punctuation">;</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span
                            class="token punctuation">.</span><font></font>
    <font></font>
    <font></font>
    <span class="token keyword">public</span> <span class="token function">GTVGApplication</span><span
                            class="token punctuation">(</span><span class="token keyword">final</span> ServletContext servletContext<span
                            class="token punctuation">)</span> <span class="token punctuation">{</span><font></font>
<font></font>
        <span class="token keyword">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span><font></font>
<font></font>
        ServletContextTemplateResolver templateResolver <span class="token operator">=</span>
                <span class="token keyword">new</span> <span
                            class="token class-name">ServletContextTemplateResolver</span><span
                            class="token punctuation">(</span>servletContext<span
                            class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
        <font></font>
        <span class="token comment" spellcheck="true">// HTML is the default mode, but we set it anyway for better understanding of code</span>
        templateResolver<span class="token punctuation">.</span><span class="token function">setTemplateMode</span><span
                            class="token punctuation">(</span>TemplateMode<span
                            class="token punctuation">.</span>HTML<span class="token punctuation">)</span><span
                            class="token punctuation">;</span>
        <span class="token comment"
              spellcheck="true">// This will convert "home" to "/WEB-INF/templates/home.html"</span>
        templateResolver<span class="token punctuation">.</span><span class="token function">setPrefix</span><span
                            class="token punctuation">(</span><span
                            class="token string">"/WEB-INF/templates/"</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
        templateResolver<span class="token punctuation">.</span><span class="token function">setSuffix</span><span
                            class="token punctuation">(</span><span class="token string">".html"</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">// Template cache TTL=1h. If not set, entries would be cached until expelled by LRU</span>
        templateResolver<span class="token punctuation">.</span><span class="token function">setCacheTTLMs</span><span
                            class="token punctuation">(</span>Long<span class="token punctuation">.</span><span
                            class="token function">valueOf</span><span class="token punctuation">(</span>3600000L<span
                            class="token punctuation">)</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span><font></font>
        <font></font>
        <span class="token comment" spellcheck="true">// Cache is set to true by default. Set to false if you want templates to</span>
        <span class="token comment" spellcheck="true">// be automatically updated when modified.</span>
        templateResolver<span class="token punctuation">.</span><span class="token function">setCacheable</span><span
                            class="token punctuation">(</span><span class="token boolean">true</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
        <font></font>
        <span class="token keyword">this</span><span class="token punctuation">.</span>templateEngine <span
                            class="token operator">=</span> <span class="token keyword">new</span> <span
                            class="token class-name">TemplateEngine</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>templateEngine<span
                            class="token punctuation">.</span><span
                            class="token function">setTemplateResolver</span><span class="token punctuation">(</span>templateResolver<span
                            class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
        <font></font>
        <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><font></font>
<font></font>
    <span class="token punctuation">}</span><font></font>
<font></font>
<span class="token punctuation">}</span></code></pre>
                <p><font><font>配置</font></font><code>TemplateEngine</code><font><font>对象</font><font>有很多种方法</font><font>，但现在这几行代码将足够教给我们所需的步骤。</font></font>
                </p>
                <section class="level3" id="the-template-resolver">
                    <h3><font><font>模板解析器</font></font></h3>
                    <p><font><font>我们从模板解析器开始：</font></font></p>
                    <pre class="  language-java"><code class="  language-java">ServletContextTemplateResolver templateResolver <span
                            class="token operator">=</span>
        <span class="token keyword">new</span> <span class="token class-name">ServletContextTemplateResolver</span><span
                                class="token punctuation">(</span>servletContext<span class="token punctuation">)</span><span
                                class="token punctuation">;</span></code></pre>
                    <p><font><font>模板解析器是实现Thymeleaf API接口的对象，称为</font></font><code>org.thymeleaf.templateresolver.ITemplateResolver</code><font><font>：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java"><span class="token keyword">public</span> <span
                            class="token keyword">interface</span> <span
                            class="token class-name">ITemplateResolver</span> <span
                            class="token punctuation">{</span><font></font>
<font></font>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span
                                class="token punctuation">.</span><font></font>
  <font></font>
    <span class="token comment" spellcheck="true">/*
     * Templates are resolved by their name (or content) and also (optionally) their
     * owner template in case we are trying to resolve a fragment for another template.
     * Will return null if template cannot be handled by this template resolver.
     */</span>
    <span class="token keyword">public</span> TemplateResolution <span
                                class="token function">resolveTemplate</span><span class="token punctuation">(</span>
            <span class="token keyword">final</span> IEngineConfiguration configuration<span
                                class="token punctuation">,</span>
            <span class="token keyword">final</span> String ownerTemplate<span class="token punctuation">,</span> <span
                                class="token keyword">final</span> String template<span
                                class="token punctuation">,</span>
            <span class="token keyword">final</span> Map<span class="token operator">&lt;</span>String<span
                                class="token punctuation">,</span> Object<span class="token operator">&gt;</span> templateResolutionAttributes<span
                                class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
                    <p>These objects are in charge of determining how our templates will be accessed, and in this GTVG
                        application, the <code>org.thymeleaf.templateresolver.ServletContextTemplateResolver</code>
                        means that we are going to retrieve our template files as resources from the <em>Servlet
                            Context</em>: an application-wide <code>javax.servlet.ServletContext</code> object that
                        exists in every Java web application, and that resolves resources from the web application root.
                    </p>
                    <p>But that’s not all we can say about the template resolver, because we can set some configuration
                        parameters on it. First, the template mode:</p>
                    <pre class="  language-java"><code class="  language-java">templateResolver<span
                            class="token punctuation">.</span><span class="token function">setTemplateMode</span><span
                            class="token punctuation">(</span>TemplateMode<span
                            class="token punctuation">.</span>HTML<span class="token punctuation">)</span><span
                            class="token punctuation">;</span></code></pre>
                    <p>HTML is the default template mode for <code>ServletContextTemplateResolver</code>, but it is good
                        practice to establish it anyway so that our code documents clearly what is going on.</p>
                    <pre class="  language-java"><code class="  language-java">templateResolver<span
                            class="token punctuation">.</span><span class="token function">setPrefix</span><span
                            class="token punctuation">(</span><span
                            class="token string">"/WEB-INF/templates/"</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
templateResolver<span class="token punctuation">.</span><span class="token function">setSuffix</span><span
                                class="token punctuation">(</span><span class="token string">".html"</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    <p>The <em>prefix</em> and <em>suffix</em> modify the template names that we will be passing to the
                        engine for obtaining the real resource names to be used.</p>
                    <p>Using this configuration, the template name <em>“product/list”</em> would correspond to:</p>
                    <pre class="  language-java"><code class="  language-java">servletContext<span
                            class="token punctuation">.</span><span
                            class="token function">getResourceAsStream</span><span
                            class="token punctuation">(</span><span class="token string">"/WEB-INF/templates/product/list.html"</span><span
                            class="token punctuation">)</span></code></pre>
                    <p>Optionally, the amount of time that a parsed template can live in the cache is configured at the
                        Template Resolver by means of the <em>cacheTTLMs</em> property:</p>
                    <pre class="  language-java"><code class="  language-java">templateResolver<span
                            class="token punctuation">.</span><span class="token function">setCacheTTLMs</span><span
                            class="token punctuation">(</span>3600000L<span class="token punctuation">)</span><span
                            class="token punctuation">;</span></code></pre>
                    <p>A template can still be expelled from cache before that TTL is reached if the max cache size is
                        reached and it is the oldest entry currently cached.</p>
                    <blockquote>
                        <p>Cache behaviour and sizes can be defined by the user by implementing the
                            <code>ICacheManager</code> interface or by modifying the <code>StandardCacheManager</code>
                            object to manage the default cache.</p>
                    </blockquote>
                    <p><font><font>有更多的了解模板解析器，但现在我们来看看我们的模板引擎对象的创建。</font></font></p>
                </section>
                <section class="level3" id="the-template-engine">
                    <h3><font><font>模板引擎</font></font></h3>
                    <p><font><font>Template
                        Engine对象是接口的</font></font><code>org.thymeleaf.ITemplateEngine</code><font><font>实现。</font><font>其中一个实现由Thymeleaf核心提供：</font></font><code>org.thymeleaf.TemplateEngine</code><font><font>我们在此创建一个实例：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java">templateEngine <span
                            class="token operator">=</span> <span class="token keyword">new</span> <span
                            class="token class-name">TemplateEngine</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
templateEngine<span class="token punctuation">.</span><span class="token function">setTemplateResolver</span><span
                                class="token punctuation">(</span>templateResolver<span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    <p><font><font>相当简单，不是吗？</font><font>我们所需要的就是创建一个实例并将Template Resolver设置为它。</font></font></p>
                    <p>
                        <font><font>模板解析器是唯一</font></font><em><font><font>需要的</font></font></em><font><font>参数</font></font><code>TemplateEngine</code><font><font>，尽管还有很多其他参数将被覆盖（消息解析器，缓存大小等）。</font><font>现在，这就是我们所需要的。</font></font>
                    </p>
                    <p><font><font>我们的模板引擎现在已经准备就绪，我们可以开始使用Thymeleaf创建我们的页面。</font></font></p>
                </section>
            </section>
        </section>
        <section class="level1" id="using-texts">
            <h1><font><font>3使用文本</font></font></h1>
            <section class="level2" id="a-multi-language-welcome">
                <h2><font><font>3.1多语言欢迎</font></font></h2>
                <p><font><font>我们的第一个任务是为我们的杂货店创建一个主页。</font></font></p>
                <p><font><font>该页面的第一个版本将非常简单：只需一个标题和一个欢迎信息。</font><font>这是我们的</font></font><code>/WEB-INF/templates/home.html</code><font><font>文件：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span
        class="token attr-name"><span class="token namespace">xmlns:</span>th</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span><a href="http://www.thymeleaf.org"
                                                                                     rel="noreferrer"
                                                                                     style="cursor:help;display:inline !important;"
                                                                                     target="_blank">http://www.thymeleaf.org</a><span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
            class="token punctuation">&gt;</span></span>Good Thymes Virtual Grocery<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span
            class="token attr-name">http-equiv</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>Content-Type<span
            class="token punctuation">"</span></span> <span class="token attr-name">content</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/html; charset<span
            class="token punctuation">=</span>UTF-8<span class="token punctuation">"</span></span> <span
            class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
            class="token attr-name">rel</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>stylesheet<span
            class="token punctuation">"</span></span> <span class="token attr-name">type</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
            class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all<span
            class="token punctuation">"</span></span>
          <span class="token attr-name">href</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>../../css/gtvg.css<span
                class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>@{/css/gtvg.css}<span class="token punctuation">"</span></span> <span
                class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>#{home.welcome}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Welcome to our grocery store!<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>您会注意到的第一件事是，该文件是HTML5，可以由任何浏览器正确显示，因为它不包括任何非HTML标签（浏览器忽略他们不明白的所有属性，如</font></font><code>th:text</code><font><font>）。</font></font>
                </p>
                <p><font><font>但是您也可能会注意到，此模板并不是一个真正</font></font><em><font><font>有效的</font></font></em><font><font>
                    HTML5文档，因为HTML5格式不允许我们以</font></font><code>th:*</code><font><font>表单形式</font><font>使用这些非标准</font><font>属性。</font><font>事实上，我们甚至添加了一个</font></font><code>xmlns:th</code><font><font>属性到我们的</font></font><code>&lt;html&gt;</code><font><font>标签，绝对非HTML5-ish的东西：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>html</span> <span
                        class="token attr-name"><span class="token namespace">xmlns:</span>th</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span><a href="http://www.thymeleaf.org" rel="noreferrer"
                                                             style="cursor:help;display:inline !important;"
                                                             target="_blank">http://www.thymeleaf.org</a><span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>...在模板处理中完全没有影响，但作为一个</font></font><em><font><font>咒语</font></font></em><font><font>，阻止我们的IDE抱怨缺少所有这些</font></font><code>th:*</code><font><font>属性的命名空间定义。</font></font>
                </p>
                <p><font><font>那么如果我们想让这个模板</font></font><strong><font><font>HTML5有效</font></font></strong><font><font>呢？</font><font>Easy：切换到Thymeleaf的数据属性语法，使用</font></font><code>data-</code><font><font>属性名称</font><font>的</font><font>前缀和连字符（</font></font><code>-</code><font><font>）分隔符而不是分号（</font></font><code>:</code><font><font>）：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span
        class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
            class="token punctuation">&gt;</span></span>Good Thymes Virtual Grocery<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span
            class="token attr-name">http-equiv</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>Content-Type<span
            class="token punctuation">"</span></span> <span class="token attr-name">content</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/html; charset<span
            class="token punctuation">=</span>UTF-8<span class="token punctuation">"</span></span> <span
            class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
            class="token attr-name">rel</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>stylesheet<span
            class="token punctuation">"</span></span> <span class="token attr-name">type</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
            class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all<span
            class="token punctuation">"</span></span>
          <span class="token attr-name">href</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>../../css/gtvg.css<span
                class="token punctuation">"</span></span> <span class="token attr-name">data-th-href</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>@{/css/gtvg.css}<span class="token punctuation">"</span></span> <span
                class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
            class="token attr-name">data-th-text</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>#{home.welcome}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Welcome to our grocery store!<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font></font><code>data-</code><font><font>HTML5规范允许</font><font>自定义</font><font>前缀属性，因此，使用上面的代码，我们的模板将是一个</font></font><em><font><font>有效的HTML5文档</font></font></em><font><font>。</font></font>
                </p>
                <blockquote>
                    <p>
                        <font><font>两个符号是完全等价的和可互换的，但是为了简化和紧凑的代码示例，本教程将使用</font></font><em><font><font>命名空间符号</font></font></em><font><font>（</font></font><code>th:*</code><font><font>）。</font><font>此外，</font></font><code>th:*</code><font><font>符号在每个Thymeleaf模板模式（</font></font><code>XML</code><font><font>，</font></font><code>TEXT</code><font><font>...）</font><font>中更为通用且允许，</font><font>而</font></font><code>data-</code><font><font>符号仅允许在</font></font><code>HTML</code><font><font>模式下。</font></font>
                    </p>
                </blockquote>
                <section class="level3" id="using-thtext-and-externalizing-text">
                    <h3><font><font>使用th：文本和外部化文本</font></font></h3>
                    <p><font><font
                            class="">外部化文本是从模板文件中提取模板代码的片段，以便它们可以保存在单独的文件（通常为</font></font><code>.properties</code><font><font
                            class="">文件）中，并且可以轻松地替换为用其他语言编写的等效文本（称为</font></font><em><font><font
                            class="">国际化</font></font></em><font><font class="">或仅仅是</font><em><font
                            class="">i18n</font></em><font
                            class="">）。</font><font>文本的外在片段通常被称为</font></font><em><font><font>“信息”</font></font></em><font><font>。</font></font>
                    </p>
                    <p>
                        <font><font>消息总是具有标识它们的密钥，而Thymeleaf允许您指定文本应与具有</font></font><code>#{...}</code><font><font>语法</font><font>的特定消息对应</font><font>：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>text</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>#{home.welcome}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Welcome to our grocery store!<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font class="">我们在这里可以看到的其实是Thymeleaf标准方言的两个不同特征：</font></font></p>
                    <ul>
                        <li><font><font class="">该</font></font><code>th:text</code><font><font class="">属性评估其值表达式并将结果设置为主机标签的主体，有效地替换了代码中我们看到的“欢迎使用我们的杂货店！”文本。</font></font>
                        </li>
                        <li><font><font class="">的</font></font><code>#{home.welcome}</code><font><font
                                class="">表达，在指定的</font></font><em><font><font
                                class="">标准表达式语法</font></font></em><font><font class="">，指示要由所使用的文本</font></font><code>th:text</code><font><font
                                class="">属性应与该消息</font></font><code>home.welcome</code><font><font class="">对应于哪个语言环境，我们正在处理与模板键。</font></font>
                        </li>
                    </ul>
                    <p><font><font class="">现在，这个外部化文本在哪里？</font></font></p>
                    <p><font><font>Thymeleaf中的外部化文本的位置是完全可配置的，它将取决于</font></font><code>org.thymeleaf.messageresolver.IMessageResolver</code><font><font>所使用</font><font>的具体</font><font>实现。</font><font
                            class="">通常，将使用基于</font></font><code>.properties</code><font><font class="">文件的实现，但是如果我们想要从数据库获取消息，我们可以创建自己的实现。</font></font>
                    </p>
                    <p>
                        <font><font>但是，我们还没有指定我们的初始化过程中模板引擎的消息解析器，这意味着我们的应用程序正在使用</font></font><em><font><font>标准信息解析器</font></font></em><font><font>，通过实施</font></font><code>org.thymeleaf.messageresolver.StandardMessageResolver</code><font><font>。</font></font>
                    </p>
                    <p><font><font>标准消息解析器希望</font></font><code>/WEB-INF/templates/home.html</code><font><font>在同一文件夹中的属性文件中</font><font>找到</font><font>与模板相同名称的消息，如：</font></font>
                    </p>
                    <ul>
                        <li><code>/WEB-INF/templates/home_en.properties</code><font><font> 英文文本。</font></font></li>
                        <li><code>/WEB-INF/templates/home_es.properties</code><font><font class="">
                            用于西班牙语文本。</font></font></li>
                        <li><code>/WEB-INF/templates/home_pt_BR.properties</code><font><font>
                            用于葡萄牙语（巴西）语言文本。</font></font></li>
                        <li><code>/WEB-INF/templates/home.properties</code><font><font> 对于默认文本（如果语言环境不匹配）。</font></font>
                        </li>
                    </ul>
                    <p><font><font>我们来看看我们的</font></font><code>home_es.properties</code><font><font>文件：</font></font>
                    </p>
                    <pre><code>home.welcome=¡Bienvenido a nuestra tienda de comestibles!</code></pre>
                    <p><font><font>这就是我们所需要的，让我们制作我们的模板。</font><font>然后让我们创建我们的家庭控制器。</font></font></p>
                </section>
                <section class="level3" id="contexts">
                    <h3><font><font>上下文</font></font></h3>
                    <p><font><font>为了处理我们的模板，我们将创建一个</font><font>实现我们以前看到</font></font><code>HomeController</code><font><font>的</font></font><code>IGTVGController</code><font><font>界面</font><font>的</font><font>类</font><font>：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java"><span class="token keyword">public</span> <span
                            class="token keyword">class</span> <span
                            class="token class-name">HomeController</span> <span class="token keyword">implements</span> <span
                            class="token class-name">IGTVGController</span> <span
                            class="token punctuation">{</span><font></font>
<font></font>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">process</span><span
                                class="token punctuation">(</span>
            <span class="token keyword">final</span> HttpServletRequest request<span class="token punctuation">,</span> <span
                                class="token keyword">final</span> HttpServletResponse response<span
                                class="token punctuation">,</span>
            <span class="token keyword">final</span> ServletContext servletContext<span
                                class="token punctuation">,</span> <span class="token keyword">final</span> ITemplateEngine templateEngine<span
                                class="token punctuation">)</span>
            <span class="token keyword">throws</span> Exception <span class="token punctuation">{</span><font></font>
        <font></font>
        WebContext ctx <span class="token operator">=</span>
                <span class="token keyword">new</span> <span class="token class-name">WebContext</span><span
                                class="token punctuation">(</span>request<span class="token punctuation">,</span> response<span
                                class="token punctuation">,</span> servletContext<span
                                class="token punctuation">,</span> request<span class="token punctuation">.</span><span
                                class="token function">getLocale</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span><font></font>
        <font></font>
        templateEngine<span class="token punctuation">.</span><span class="token function">process</span><span
                                class="token punctuation">(</span><span class="token string">"home"</span><span
                                class="token punctuation">,</span> ctx<span
                                class="token punctuation">,</span> response<span class="token punctuation">.</span><span
                                class="token function">getWriter</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span><font></font>
        <font></font>
    <span class="token punctuation">}</span><font></font>
<font></font>
<span class="token punctuation">}</span></code></pre>
                    <p>
                        <font><font>我们首先看到的是创建一个</font></font><em><font><font>上下文</font></font></em><font><font>。</font><font>Thymeleaf上下文是实现该</font></font><code>org.thymeleaf.context.IContext</code><font><font>接口</font><font>的对象</font><font>。</font><font
                            class="">上下文应包含在变量映射中执行模板引擎所需的所有数据，并且还引用必须用于外部化消息的区域设置。</font></font></p>
                    <pre class="  language-java"><code class="  language-java"><span class="token keyword">public</span> <span
                            class="token keyword">interface</span> <span class="token class-name">IContext</span> <span
                            class="token punctuation">{</span><font></font>
<font></font>
    <span class="token keyword">public</span> Locale <span class="token function">getLocale</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">boolean</span> <span class="token function">containsVariable</span><span
                                class="token punctuation">(</span><span
                                class="token keyword">final</span> String name<span
                                class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> Set<span class="token operator">&lt;</span>String<span
                                class="token operator">&gt;</span> <span
                                class="token function">getVariableNames</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    <span class="token keyword">public</span> Object <span class="token function">getVariable</span><span
                                class="token punctuation">(</span><span
                                class="token keyword">final</span> String name<span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
    <font></font>
<span class="token punctuation">}</span></code></pre>
                    <p><font><font>这个接口有一个专门的扩展</font></font><code>org.thymeleaf.context.IWebContext</code><font><font>，意在用于基于ServletAPI的Web应用程序（如SpringMVC）。</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java"><span class="token keyword">public</span> <span
                            class="token keyword">interface</span> <span
                            class="token class-name">IWebContext</span> <span class="token keyword">extends</span> <span
                            class="token class-name">IContext</span> <span
                            class="token punctuation">{</span><font></font>
    <font></font>
    <span class="token keyword">public</span> HttpServletRequest <span class="token function">getRequest</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    <span class="token keyword">public</span> HttpServletResponse <span class="token function">getResponse</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    <span class="token keyword">public</span> HttpSession <span class="token function">getSession</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    <span class="token keyword">public</span> ServletContext <span class="token function">getServletContext</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span><font></font>
    <font></font>
<span class="token punctuation">}</span></code></pre>
                    <p><font><font>Thymeleaf核心库提供了以下每个接口的实现：</font></font></p>
                    <ul>
                        <li><code>org.thymeleaf.context.Context</code><font><font>
                            工具 </font></font><code>IContext</code></li>
                        <li><code>org.thymeleaf.context.WebContext</code><font><font>
                            工具 </font></font><code>IWebContext</code></li>
                    </ul>
                    <p>
                        <font><font>而在控制器代码中可以看到，</font></font><code>WebContext</code><font><font>是我们使用的</font><font>代码</font><font>。</font><font>其实我们必须，因为使用一个</font></font><code>ServletContextTemplateResolver</code><font><font>要求我们使用一个上下文来实现</font></font><code>IWebContext</code><font><font>。</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java">WebContext ctx <span
                            class="token operator">=</span> <span class="token keyword">new</span> <span
                            class="token class-name">WebContext</span><span
                            class="token punctuation">(</span>request<span
                            class="token punctuation">,</span> response<span class="token punctuation">,</span> servletContext<span
                            class="token punctuation">,</span> request<span class="token punctuation">.</span><span
                            class="token function">getLocale</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span></code></pre>
                    <p><font><font>只需要这四个构造函数参数中的三个，因为如果没有指定，那么将使用系统的默认语言环境（尽管不应该在实际应用程序中发生）。</font></font></p>
                    <p>
                        <font><font>有一些专门的表达式，我们将能够使用它们从</font></font><code>WebContext</code><font><font>我们的模板</font><font>中获取请求参数和请求，会话和应用程序</font><font>属性。</font><font>例如：</font></font>
                    </p>
                    <ul>
                        <li>
                            <code>${x}</code><font><font>将返回</font></font><code>x</code><font><font>存储到Thymeleaf上下文中</font><font>的变量</font><font>或作为</font></font><em><font><font>请求属性</font></font></em><font><font>。</font></font>
                        </li>
                        <li>
                            <code>${param.x}</code><font><font>会返回一个</font></font><em><font><font>请求参数</font></font></em><font><font>叫</font></font><code>x</code><font><font>（可能是多值）。</font></font>
                        </li>
                        <li>
                            <code>${session.x}</code><font><font>将返回一个</font><font>调用</font><font>的</font></font><em><font><font>会话属性</font></font></em><font></font><code>x</code><font><font>。</font></font>
                        </li>
                        <li><code>${application.x}</code><font><font class="">将返回一个</font><font class="">名为</font><font
                                class="">的</font></font><em><font><font
                                class="">servlet上下文属性</font></font></em><font></font><code>x</code><font><font class="">。</font></font>
                        </li>
                    </ul>
                </section>
                <section class="level3" id="executing-the-template-engine">
                    <h3><font><font>执行模板引擎</font></font></h3>
                    <p><font><font>随着我们的上下文对象准备就绪，现在我们可以告诉模板引擎使用上下文来处理模板（通过它的名字），并传递一个响应写入器，以便可以将响应写入它：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java">templateEngine<span
                            class="token punctuation">.</span><span class="token function">process</span><span
                            class="token punctuation">(</span><span class="token string">"home"</span><span
                            class="token punctuation">,</span> ctx<span class="token punctuation">,</span> response<span
                            class="token punctuation">.</span><span class="token function">getWriter</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    <p><font><font>让我们看看使用西班牙语区域的结果：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span
        class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
            class="token punctuation">&gt;</span></span>Good Thymes Virtual Grocery<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                                class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span
            class="token attr-name">content</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>text/html; charset<span
            class="token punctuation">=</span>UTF-8<span class="token punctuation">"</span></span> <span
            class="token attr-name">http-equiv</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>Content-Type<span
            class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
            class="token attr-name">rel</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>stylesheet<span
            class="token punctuation">"</span></span> <span class="token attr-name">type</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
            class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all<span
            class="token punctuation">"</span></span> <span class="token attr-name">href</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>/gtvg/css/gtvg.css<span
            class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span>¡Bienvenido a nuestra tienda de comestibles!<span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                </section>
            </section>
            <section class="level2" id="more-on-texts-and-variables">
                <h2><font><font>3.2更多文本和变量</font></font></h2>
                <section class="level3" id="unescaped-text">
                    <h3><font><font>非转义文本</font></font></h3>
                    <p><font><font>我们的主页的最简单的版本似乎已经准备好了，但是我们还没有想到什么呢？如果我们有这样的消息呢？</font></font></p>
                    <pre class="  language-java"><code class="  language-java">home<span
                            class="token punctuation">.</span>welcome<span class="token operator">=</span>Welcome to our <span
                            class="token operator">&lt;</span>b<span class="token operator">&gt;</span>fantastic<span
                            class="token operator">&lt;</span><span class="token operator">/</span>b<span
                            class="token operator">&gt;</span> grocery store<span class="token operator">!</span></code></pre>
                    <p><font><font>如果我们像以前一样执行此模板，我们将获得：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                            class="token punctuation">&gt;</span></span>Welcome to our <span class="token entity"
                                                                                             title="<">&amp;lt;</span>b<span
                            class="token entity" title=">">&amp;gt;</span>fantastic<span class="token entity" title="<">&amp;lt;</span>/b<span
                            class="token entity" title=">">&amp;gt;</span> grocery store!<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                    <p>
                        <font><font>这不是我们预期的，因为我们的</font></font><code>&lt;b&gt;</code><font><font>标签已被转义，因此它将显示在浏览器中。</font></font>
                    </p>
                    <p><font><font>这是属性的默认行为</font></font><code>th:text</code><font><font>。</font><font>如果我们希望Thymeleaf尊重我们的HTML标签，而不是逃避他们，我们将不得不使用一个不同的属性：（</font></font><code>th:utext</code><font><font>对于“unes​​caped
                        text”）：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>utext</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>#{home.welcome}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Welcome to our grocery store!<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>这将输出我们的消息就像我们想要的：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                            class="token punctuation">&gt;</span></span>Welcome to our <span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>b</span><span
                            class="token punctuation">&gt;</span></span>fantastic<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>b</span><span
                            class="token punctuation">&gt;</span></span> grocery store!<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                </section>
                <section class="level3" id="using-and-displaying-variables">
                    <h3><font><font>使用和显示变量</font></font></h3>
                    <p><font><font
                            class="">现在我们再添加一些更多的内容到我们的主页。</font><font>例如，我们可能希望在我们的欢迎信息下方显示日期，如下所示：</font></font></p>
                    <pre><code>Welcome to our fantastic grocery store!<font></font>
<font></font>
Today is: 12 july 2010</code></pre>
                    <p><font><font>首先，我们将必须修改我们的控制器，以便将该日期添加为上下文变量：</font></font></p>
                    <pre class="  language-java"><code class="  language-java"><span class="token keyword">public</span> <span
                            class="token keyword">void</span> <span class="token function">process</span><span
                            class="token punctuation">(</span>
            <span class="token keyword">final</span> HttpServletRequest request<span class="token punctuation">,</span> <span
                                class="token keyword">final</span> HttpServletResponse response<span
                                class="token punctuation">,</span>
            <span class="token keyword">final</span> ServletContext servletContext<span
                                class="token punctuation">,</span> <span class="token keyword">final</span> ITemplateEngine templateEngine<span
                                class="token punctuation">)</span>
            <span class="token keyword">throws</span> Exception <span class="token punctuation">{</span><font></font>
        <font></font>
    SimpleDateFormat dateFormat <span class="token operator">=</span> <span class="token keyword">new</span> <span
                                class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span><span
                                class="token string">"dd MMMM yyyy"</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    Calendar cal <span class="token operator">=</span> Calendar<span class="token punctuation">.</span><span
                                class="token function">getInstance</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
        <font></font>
    WebContext ctx <span class="token operator">=</span>
            <span class="token keyword">new</span> <span class="token class-name">WebContext</span><span
                                class="token punctuation">(</span>request<span class="token punctuation">,</span> response<span
                                class="token punctuation">,</span> servletContext<span
                                class="token punctuation">,</span> request<span class="token punctuation">.</span><span
                                class="token function">getLocale</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    ctx<span class="token punctuation">.</span><span class="token function">setVariable</span><span
                                class="token punctuation">(</span><span class="token string">"today"</span><span
                                class="token punctuation">,</span> dateFormat<span
                                class="token punctuation">.</span><span class="token function">format</span><span
                                class="token punctuation">(</span>cal<span class="token punctuation">.</span><span
                                class="token function">getTime</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
        <font></font>
    templateEngine<span class="token punctuation">.</span><span class="token function">process</span><span
                                class="token punctuation">(</span><span class="token string">"home"</span><span
                                class="token punctuation">,</span> ctx<span
                                class="token punctuation">,</span> response<span class="token punctuation">.</span><span
                                class="token function">getWriter</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span><font></font>
        <font></font>
<span class="token punctuation">}</span></code></pre>
                    <p>
                        <font><font>我们添加了一个</font></font><code>String</code><font><font>调用</font></font><code>today</code><font><font>我们上下文</font><font>的</font><font>变量</font><font>，现在我们可以在我们的模板中显示它：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>body</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
          class="token attr-name"><span class="token namespace">th:</span>utext</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>#{home.welcome}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Welcome to our grocery store!<span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Today is: <span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                                class="token namespace">th:</span>text</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span class="token punctuation">"</span>${today}<span
                                class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>13 February 2011<span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                                class="token punctuation">&gt;</span></span><span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                                class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p>
                        <font><font>正如你所看到的，我们仍然使用该</font></font><code>th:text</code><font><font>作业</font><font>的</font><font>属性（这是正确的，因为我们要替换标签的正文），但是这一次语法有点不同，而不是一个</font></font><code>#{...}</code><font><font>表达式值，我们使用</font></font><code>${...}</code><font><font>一。</font><font>这是一个</font></font><strong><font><font>变量表达式</font></font></strong><font><font>，它包含一个名为</font></font><em><font><font>OGNL（Object-Graph
                        Navigation Language）的表达式</font></font></em><font><font>，它将在之前讨论的上下文变量映射上执行。</font></font></p>
                    <p>
                        <font><font>该</font></font><code>${today}</code><font><font>表达式只是表示“今天拿到称为变量”，但这些表述可能更加复杂（如</font></font><code>${user.name}</code><font><font>“获取被叫用户的变量，并调用它的</font></font><code>getName()</code><font><font>方法”）。</font></font>
                    </p>
                    <p><font><font>属性值有很多可能性：消息，变量表达式...等等。</font><font>下一章将向大家介绍一下这些可能性。</font></font></p>
                </section>
            </section>
        </section>
        <section class="level1" id="standard-expression-syntax">
            <h1><font><font>4标准表达式语法</font></font></h1>
            <p><font><font>我们将在我们的杂货虚拟商店的开发中休息一下，了解“Thymeleaf”标准方言中最重要的部分之一：Thymeleaf标准表达式语法。</font></font></p>
            <p><font><font class="">我们已经看到了两种类型的有效的属性值，以这种语法表示：消息和变量表达式：</font></font></p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name"><span
                    class="token namespace">th:</span>utext</span><span class="token attr-value"><span
                    class="token punctuation">=</span><span class="token punctuation">"</span>#{home.welcome}<span
                    class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Welcome to our grocery store!<span
                    class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                    class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
        class="token punctuation">&gt;</span></span>Today is: <span class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                        class="token namespace">th:</span>text</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>${today}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>13 february 2011<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>但是，有更多类型的表达和更多有趣的细节来了解我们已经知道的内容。</font><font>首先，我们来看看标准表达式功能的快速总结：</font></font></p>
            <ul>
                <li><font><font>简单表达式：
                </font></font>
                    <ul>
                        <li><font><font>可变表达式： </font></font><code>${...}</code></li>
                        <li><font><font>选择变量表达式： </font></font><code>*{...}</code></li>
                        <li><font><font>消息表达式： </font></font><code>#{...}</code></li>
                        <li><font><font>链接网址表达式： </font></font><code>@{...}</code></li>
                        <li><font><font>片段表达式： </font></font><code>~{...}</code></li>
                    </ul>
                </li>
                <li><font><font>文字
                </font></font>
                    <ul>
                        <li><font><font>文本文字：</font></font><code>'one text'</code><font><font>，</font></font><code>'Another
                            one!'</code><font><font>，...</font></font></li>
                        <li>
                            <font><font>号码文字：</font></font><code>0</code><font><font>，</font></font><code>34</code><font><font>，</font></font><code>3.0</code><font><font>，</font></font><code>12.3</code><font><font>，...</font></font>
                        </li>
                        <li>
                            <font><font>布尔文字：</font></font><code>true</code><font><font>，</font></font><code>false</code>
                        </li>
                        <li><font><font>空字面： </font></font><code>null</code></li>
                        <li>
                            <font><font>文字标记：</font></font><code>one</code><font><font>，</font></font><code>sometext</code><font><font>，</font></font><code>main</code><font><font>，...</font></font>
                        </li>
                    </ul>
                </li>
                <li><font><font>文字操作：
                </font></font>
                    <ul>
                        <li><font><font>字符串连接： </font></font><code>+</code></li>
                        <li><font><font>文字替代： </font></font><code>|The name is ${name}|</code></li>
                    </ul>
                </li>
                <li><font><font>算术运算：
                </font></font>
                    <ul>
                        <li>
                            <font><font>二元运算符：</font></font><code>+</code><font><font>，</font></font><code>-</code><font><font>，</font></font><code>*</code><font><font>，</font></font><code>/</code><font><font>，</font></font><code>%</code>
                        </li>
                        <li><font><font>减号（一元运算符）： </font></font><code>-</code></li>
                    </ul>
                </li>
                <li><font><font>布尔运算：
                </font></font>
                    <ul>
                        <li><font><font>二元运算符：</font></font><code>and</code><font><font>，</font></font><code>or</code>
                        </li>
                        <li><font><font class="">布尔否定（一元运算符）： </font></font><code>!</code><font><font class="">，</font></font><code>not</code>
                        </li>
                    </ul>
                </li>
                <li><font><font>比较和平等：
                </font></font>
                    <ul>
                        <li>
                            <font><font>比较：</font></font><code>&gt;</code><font><font>，</font></font><code>&lt;</code><font><font>，</font></font><code>&gt;=</code><font><font>，</font></font><code>&lt;=</code><font><font>（</font></font><code>gt</code><font><font>，</font></font><code>lt</code><font><font>，</font></font><code>ge</code><font><font>，</font></font><code>le</code><font><font>）</font></font>
                        </li>
                        <li>
                            <font><font>平等运营商：</font></font><code>==</code><font><font>，</font></font><code>!=</code><font><font>（</font></font><code>eq</code><font><font>，</font></font><code>ne</code><font><font>）</font></font>
                        </li>
                    </ul>
                </li>
                <li><font><font>条件运算符：
                </font></font>
                    <ul>
                        <li><font><font>如果 - 那么： </font></font><code>(if) ? (then)</code></li>
                        <li><font><font>If-then-else： </font></font><code>(if) ? (then) : (else)</code></li>
                        <li><font><font>默认： </font></font><code>(value) ?: (defaultvalue)</code></li>
                    </ul>
                </li>
                <li><font><font>特殊令牌：
                </font></font>
                    <ul>
                        <li><font><font>无操作： </font></font><code>_</code></li>
                    </ul>
                </li>
            </ul>
            <p><font><font>所有这些功能可以组合和嵌套：</font></font></p>
            <pre class="  language-html"><code class="  language-html">'User is of type ' + (${user.isAdmin()} ? 'Administrator' : (${user.type} ?: 'Unknown'))</code></pre>
            <section class="level2" id="messages">
                <h2><font><font>4.1消息</font></font></h2>
                <p><font><font>我们已经知道，</font></font><code>#{...}</code><font><font>消息表达式允许我们链接：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>utext</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>#{home.welcome}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>Welcome to our grocery store!<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>...到这个：</font></font></p>
                <pre class="  language-html"><code class="  language-html">home.welcome=¡Bienvenido a nuestra tienda de comestibles!</code></pre>
                <p><font><font>但是还有一个方面我们还没有想到：如果消息文本不是完全静态的，会发生什么？</font><font>例如，如果我们的应用程序知道谁是用户在任何时候访问该网站，我们是否想通过名字问候？</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>¡Bienvenido a nuestra tienda de comestibles, John Apricot!<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这意味着我们需要在我们的消息中添加一个参数。</font><font>像这样：</font></font></p>
                <pre class="  language-html"><code class="  language-html">home.welcome=¡Bienvenido a nuestra tienda de comestibles, {0}!</code></pre>
                <p>
                    <font><font>根据</font></font><code>java.text.MessageFormat</code><font><font>标准语法</font><font>指定</font><font>参数，这意味着您可以格式化为这些类的API文档中指定的数字和日期。</font></font>
                </p>
                <p><font><font>为了指定我们的参数的值，并给出一个HTTP会话属性</font></font><code>user</code><font><font>，我们将具有：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>utext</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>#{home.welcome(${session.user.name})}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
  Welcome to our grocery store, Sebastian Pepper!<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>可以指定几个参数，用逗号分隔。</font><font>实际上，消息密钥本身可以来自一个变量：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>utext</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>#{${welcomeMsgKey}(${session.user.name})}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
  Welcome to our grocery store, Sebastian Pepper!<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="variables">
                <h2><font><font>4.2变量</font></font></h2>
                <p><font><font class="">我们已经提到，</font></font><code>${...}</code><font><font class="">表达式实际上是在上下文中包含的变量的映射上执行的OGNL（Object-Graph
                    Navigation Language）对象。</font></font></p>
                <blockquote>
                    <p><font><font>有关OGNL语法和功能的详细信息，请阅读</font></font><a
                            href="http://commons.apache.org/ognl/"><font><font>OGNL语言指南</font></font></a></p>
                    <p><font><font>在Spring MVC启用的应用程序中，OGNL将被替换为</font></font><strong><font><font>SpringEL</font></font></strong><font><font>，但其语法与OGNL非常相似（实际上，在大多数常见情况下完全相同）。</font></font>
                    </p>
                </blockquote>
                <p><font><font>从OGNL的语法，我们知道：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>Today is: <span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${today}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>13 february 2011<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>.<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>实际上相当于：</font></font></p>
                <pre class="  language-java"><code class="  language-java">ctx<span
                        class="token punctuation">.</span><span class="token function">getVariable</span><span
                        class="token punctuation">(</span><span class="token string">"today"</span><span
                        class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                <p><font><font>但是，OGNL允许我们创建更强大的表达式，这就是：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>utext</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>#{home.welcome(${session.user.name})}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
  Welcome to our grocery store, Sebastian Pepper!<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>...通过执行以下命令获取用户名：</font></font></p>
                <pre class="  language-java"><code class="  language-java"><span class="token punctuation">(</span><span
                        class="token punctuation">(</span>User<span class="token punctuation">)</span> ctx<span
                        class="token punctuation">.</span><span class="token function">getVariable</span><span
                        class="token punctuation">(</span><span class="token string">"session"</span><span
                        class="token punctuation">)</span><span class="token punctuation">.</span><span
                        class="token function">get</span><span class="token punctuation">(</span><span
                        class="token string">"user"</span><span class="token punctuation">)</span><span
                        class="token punctuation">)</span><span class="token punctuation">.</span><span
                        class="token function">getName</span><span class="token punctuation">(</span><span
                        class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                <p><font><font>但是getter方法导航只是OGNL的一个功能。</font><font>我们再来看一下：</font></font></p>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * Access to properties using the point (.). Equivalent to calling property getters.
 */</span>
$<span class="token punctuation">{</span>person<span class="token punctuation">.</span>father<span
                            class="token punctuation">.</span>name<span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Access to properties can also be made by using brackets ([]) and writing
 * the name of the property as a variable or between single quotes.
 */</span>
$<span class="token punctuation">{</span>person<span class="token punctuation">[</span><span class="token string">'father'</span><span
                            class="token punctuation">]</span><span class="token punctuation">[</span><span
                            class="token string">'name'</span><span class="token punctuation">]</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * If the object is a map, both dot and bracket syntax will be equivalent to
 * executing a call on its get(...) method.
 */</span>
$<span class="token punctuation">{</span>countriesByCode<span class="token punctuation">.</span>ES<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>personsByName<span class="token punctuation">[</span><span
                            class="token string">'Stephen Zucchini'</span><span class="token punctuation">]</span><span
                            class="token punctuation">.</span>age<span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Indexed access to arrays or collections is also performed with brackets,
 * writing the index without quotes.
 */</span>
$<span class="token punctuation">{</span>personsArray<span class="token punctuation">[</span><span class="token number">0</span><span
                            class="token punctuation">]</span><span class="token punctuation">.</span>name<span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Methods can be called, even with arguments.
 */</span>
$<span class="token punctuation">{</span>person<span class="token punctuation">.</span><span class="token function">createCompleteName</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>person<span class="token punctuation">.</span><span class="token function">createCompleteNameWithSeparator</span><span
                            class="token punctuation">(</span><span class="token string">'-'</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span></code></pre>
                <section class="level3" id="expression-basic-objects">
                    <h3><font><font>表达式基本对象</font></font></h3>
                    <p><font><font>当对上下文变量评估OGNL表达式时，某些对象可用于表达式以获得更高的灵活性。</font><font>这些对象将被引用（按照OGNL标准），从</font></font><code>#</code><font><font>符号</font><font>开始</font><font>：</font></font>
                    </p>
                    <ul>
                        <li><code>#ctx</code><font><font>：上下文对象。</font></font></li>
                        <li><code>#vars:</code><font><font> 上下文变量。</font></font></li>
                        <li><code>#locale</code><font><font>：上下文区域设置。</font></font></li>
                        <li>
                            <code>#request</code><font><font>：（仅在Web上下文中）</font></font><code>HttpServletRequest</code><font><font>对象。</font></font>
                        </li>
                        <li><code>#response</code><font><font>：（仅在Web上下文中）</font></font><code>HttpServletResponse</code><font><font>对象。</font></font>
                        </li>
                        <li>
                            <code>#session</code><font><font>：（仅在Web上下文中）</font></font><code>HttpSession</code><font><font>对象。</font></font>
                        </li>
                        <li>
                            <code>#servletContext</code><font><font>：（仅在Web上下文中）</font></font><code>ServletContext</code><font><font>对象。</font></font>
                        </li>
                    </ul>
                    <p><font><font>所以我们可以这样做：</font></font></p>
                    <pre class="  language-html"><code class="  language-html">Established locale country: <span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${#locale.country}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>US<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.</code></pre>
                    <p><font><font>您可以在</font></font><a
                            href="#appendix-a-expression-basic-objects"><font><font>附录A</font></font></a><font><font>中阅读这些对象的完整参考</font><font>。</font></font>
                    </p>
                </section>
                <section class="level3" id="expression-utility-objects">
                    <h3><font><font>表达式实用程序对象</font></font></h3>
                    <p><font><font>除了这些基本的对象之外，Thymeleaf将为我们提供一组实用对象，这些对象将帮助我们在表达式中执行常见任务。</font></font></p>
                    <ul>
                        <li><code>#execInfo</code><font><font>：有关正在处理的模板的信息。</font></font></li>
                        <li><code>#messages</code><font><font>：在变量表达式中获取外部化消息的方法，与使用＃{...}语法获得的方式相同。</font></font></li>
                        <li><code>#uris</code><font><font>：转义URL / URI部分的方法</font></font></li>
                        <li><code>#conversions</code><font><font>：执行配置的转换</font></font><em><font><font>服务</font></font></em><font><font>（如果有）的方法。</font></font>
                        </li>
                        <li>
                            <code>#dates</code><font><font>：</font></font><code>java.util.Date</code><font><font>对象的</font><font>方法</font><font>：格式化，组件提取等</font></font>
                        </li>
                        <li><code>#calendars</code><font><font>：类似</font></font><code>#dates</code><font><font>，但</font></font><code>java.util.Calendar</code><font><font>对象。</font></font>
                        </li>
                        <li><code>#numbers</code><font><font>：用于格式化数字对象的方法。</font></font></li>
                        <li>
                            <code>#strings</code><font><font>：</font></font><code>String</code><font><font>对象的</font><font>方法</font><font>：contains，startsWith，prepending
                            / appending等</font></font></li>
                        <li><code>#objects</code><font><font>：一般对象的方法。</font></font></li>
                        <li><code>#bools</code><font><font>：布尔评估的方法。</font></font></li>
                        <li><code>#arrays</code><font><font>：数组方法。</font></font></li>
                        <li><code>#lists</code><font><font>：列表的方法。</font></font></li>
                        <li><code>#sets</code><font><font>：集合的方法。</font></font></li>
                        <li><code>#maps</code><font><font>：地图方法。</font></font></li>
                        <li><code>#aggregates</code><font><font>：在数组或集合上创建聚合的方法。</font></font></li>
                        <li><code>#ids</code><font><font>：处理可能重复的id属性的方法（例如，作为迭代的结果）。</font></font></li>
                    </ul>
                    <p><font><font>您可以检查</font></font><a
                            href="#appendix-b-expression-utility-objects"><font><font>附录B</font></font></a><font><font>中每个实用程序对象提供的功能</font><font>。</font></font>
                    </p>
                </section>
                <section class="level3" id="reformatting-dates-in-our-home-page">
                    <h3><font><font>在我们的主页重新格式化日期</font></font></h3>
                    <p><font><font>现在我们知道这些实用程序对象，我们可以使用它们来改变我们在主页中显示日期的方式。</font><font>相反，在我们这样做</font></font><code>HomeController</code><font><font>：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java">SimpleDateFormat dateFormat <span
                            class="token operator">=</span> <span class="token keyword">new</span> <span
                            class="token class-name">SimpleDateFormat</span><span
                            class="token punctuation">(</span><span class="token string">"dd MMMM yyyy"</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
Calendar cal <span class="token operator">=</span> Calendar<span class="token punctuation">.</span><span
                                class="token function">getInstance</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
<font></font>
WebContext ctx <span class="token operator">=</span> <span class="token keyword">new</span> <span
                                class="token class-name">WebContext</span><span class="token punctuation">(</span>request<span
                                class="token punctuation">,</span> servletContext<span
                                class="token punctuation">,</span> request<span class="token punctuation">.</span><span
                                class="token function">getLocale</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
ctx<span class="token punctuation">.</span><span class="token function">setVariable</span><span
                                class="token punctuation">(</span><span class="token string">"today"</span><span
                                class="token punctuation">,</span> dateFormat<span
                                class="token punctuation">.</span><span class="token function">format</span><span
                                class="token punctuation">(</span>cal<span class="token punctuation">.</span><span
                                class="token function">getTime</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
<font></font>
templateEngine<span class="token punctuation">.</span><span class="token function">process</span><span
                                class="token punctuation">(</span><span class="token string">"home"</span><span
                                class="token punctuation">,</span> ctx<span
                                class="token punctuation">,</span> response<span class="token punctuation">.</span><span
                                class="token function">getWriter</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span></code></pre>
                    <p><font><font>...我们可以做到这一点：</font></font></p>
                    <pre class="  language-java"><code class="  language-java">WebContext ctx <span
                            class="token operator">=</span>
    <span class="token keyword">new</span> <span class="token class-name">WebContext</span><span
                                class="token punctuation">(</span>request<span class="token punctuation">,</span> response<span
                                class="token punctuation">,</span> servletContext<span
                                class="token punctuation">,</span> request<span class="token punctuation">.</span><span
                                class="token function">getLocale</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
ctx<span class="token punctuation">.</span><span class="token function">setVariable</span><span
                                class="token punctuation">(</span><span class="token string">"today"</span><span
                                class="token punctuation">,</span> Calendar<span class="token punctuation">.</span><span
                                class="token function">getInstance</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span><font></font>
<font></font>
templateEngine<span class="token punctuation">.</span><span class="token function">process</span><span
                                class="token punctuation">(</span><span class="token string">"home"</span><span
                                class="token punctuation">,</span> ctx<span
                                class="token punctuation">,</span> response<span class="token punctuation">.</span><span
                                class="token function">getWriter</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span></code></pre>
                    <p><font><font>...然后在视图层本身执行日期格式化：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  Today is: <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                                class="token attr-value"><span class="token punctuation">=</span><span
                                class="token punctuation">"</span>${#calendars.format(today,<span
                                class="token punctuation">'</span>dd MMMM yyyy<span class="token punctuation">'</span>)}<span
                                class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>13 May 2011<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                                class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                </section>
            </section>
            <section class="level2" id="expressions-on-selections-asterisk-syntax">
                <h2><font><font class="">4.3选择表达式（星号语法）</font></font></h2>
                <p>
                    <font><font>不仅可以将变量表达式写为</font></font><code>${...}</code><font><font>，也</font><font>可以写</font><font>为</font></font><code>*{...}</code><font><font>。</font></font>
                </p>
                <p>
                    <font><font>有一个重要的区别：星号语法评估</font></font><em><font><font>所选对象</font></font></em><font><font>而不是整个上下文的</font><font>表达式</font><font>。</font><font
                        class="">也就是说，只要没有选定的对象，美元和星号语法就会完全相同。</font></font></p>
                <p>
                    <font><font>什么是选定对象？</font><font>使用</font></font><code>th:object</code><font><font>属性的表达式</font><font>的结果</font><font>。</font><font>我们在用户个人资料（</font></font><code>userprofile.html</code><font><font>）页面中</font><font>使用一个</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html">  <span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>object</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${session.user}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span>Name: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>*{firstName}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Sebastian<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span>Surname: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>*{lastName}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Pepper<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span>Nationality: <span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>text</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>*{nationality}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Saturn<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
          class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这完全相当于：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Name: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${session.user.firstName}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Sebastian<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Surname: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${session.user.lastName}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Pepper<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Nationality: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${session.user.nationality}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Saturn<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>当然，美元和星号的语法可以混合使用：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>object</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${session.user}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Name: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>*{firstName}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Sebastian<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Surname: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${session.user.lastName}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Pepper<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Nationality: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span
                            class="token punctuation">"</span>*{nationality}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Saturn<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>当对象选择到位时，所选对象也将作为</font></font><code>#object</code><font><font>表达式变量</font><font>使用美元表达式</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>object</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${session.user}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Name: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${#object.firstName}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Sebastian<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Surname: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${session.user.lastName}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Pepper<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Nationality: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span
                            class="token punctuation">"</span>*{nationality}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Saturn<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>如上所述，如果没有执行对象选择，则美元和星号语法是等效的。</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Name: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>*{session.user.name}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Sebastian<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Surname: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>*{session.user.surname}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Pepper<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Nationality: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>*{session.user.nationality}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Saturn<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="link-urls">
                <h2><font><font>4.4链接URL</font></font></h2>
                <p><font><font>由于它们的重要性，URL是Web应用程序模板中的一流公民，而</font></font><em><font><font>Thymeleaf Standard
                    Dialect</font></font></em><font><font>具有特殊的语法，</font></font><code>@</code><font><font>语法如下：</font></font><code>@{...}</code>
                </p>
                <p><font><font class="">有不同类型的网址：</font></font></p>
                <ul>
                    <li><font><font>绝对网址： </font></font><code><a href="http://www.thymeleaf.org" rel="noreferrer"
                                                                 style="cursor:help;display:inline !important;"
                                                                 target="_blank">http://www.thymeleaf.org</a></code>
                    </li>
                    <li><font><font>相对URL，可以是：
                    </font></font>
                        <ul>
                            <li><font><font>页面相对： </font></font><code>user/login.html</code></li>
                            <li><font><font>上下文相关：（</font></font><code>/itemdetails?id=3</code><font><font>服务器中的上下文名称将自动添加）</font></font>
                            </li>
                            <li>
                                <font><font>Server-relative：（</font></font><code>~/billing/processInvoice</code><font><font>允许在同一服务器中的另一个上下文（=应用程序）中调用URL。</font></font>
                            </li>
                            <li><font><font>协议相关网址： </font></font><code>//code.jquery.com/jquery-2.0.3.min.js</code>
                            </li>
                        </ul>
                    </li>
                </ul>
                <p>
                    <font><font>这些表达式的真实处理以及它们将被转换成将被输出的URL是通过</font></font><code>org.thymeleaf.linkbuilder.ILinkBuilder</code><font><font>在</font></font><code>ITemplateEngine</code><font><font>所使用对象中</font><font>注册的接口的实现完成的</font><font>。</font></font>
                </p>
                <p><font><font class="">默认情况下，该类注册了该接口的单一实现，这</font></font><code>org.thymeleaf.linkbuilder.StandardLinkBuilder</code><font><font
                        class="">对于脱机（非Web）以及基于Servlet API的Web场景都是足够的。</font><font>其他情况（如与非ServletAPI
                    Web框架的集成）可能需要链接构建器接口的特定实现。</font></font></p>
                <p>
                    <font><font>我们来使用这个新的语法。</font><font>认识</font></font><code>th:href</code><font><font>属性：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token comment"
                                                                                 spellcheck="true">&lt;!-- Will produce '<a
                        href="http://localhost:8080/gtvg/order/details?orderId=3" rel="noreferrer"
                        style="cursor:help;display:inline !important;"
                        target="_blank">http://localhost:8080/gtvg/order/details?orderId=3</a>' (plus rewriting) --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
        class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
        class="token punctuation">"</span>details.html<span class="token punctuation">"</span></span>
   <span class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>@{<a
            href="http://localhost:8080/gtvg/order/details(orderId" rel="noreferrer"
            style="cursor:help;display:inline !important;"
            target="_blank">http://localhost:8080/gtvg/order/details(orderId</a><span
            class="token punctuation">=</span>${o.id})}<span class="token punctuation">"</span></span><span
            class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token comment" spellcheck="true">&lt;!-- Will produce '/gtvg/order/details?orderId=3' (plus rewriting) --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
        class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
        class="token punctuation">"</span>details.html<span class="token punctuation">"</span></span> <span
        class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span>@{/order/details(orderId<span
        class="token punctuation">=</span>${o.id})}<span class="token punctuation">"</span></span><span
        class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token comment"
      spellcheck="true">&lt;!-- Will produce '/gtvg/order/3/details' (plus rewriting) --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
        class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
        class="token punctuation">"</span>details.html<span class="token punctuation">"</span></span> <span
        class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
        class="token punctuation">=</span><span
        class="token punctuation">"</span>@{/order/{orderId}/details(orderId<span class="token punctuation">=</span>${o.id})}<span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>有些事情要注意：</font></font></p>
                <ul>
                    <li>
                        <code>th:href</code><font><font>是一个修饰符属性：一旦处理，它将计算要使用的链接URL，并将该值设置</font></font><code>href</code><font><font>为</font></font><code>&lt;a&gt;</code><font><font>标签的属性。</font></font>
                    </li>
                    <li><font><font>我们被允许使用表达式的URL参数（如您所见</font></font><code>orderId=${o.id}</code><font><font>）。</font><font>所需的URL参数编码操作也将自动执行。</font></font>
                    </li>
                    <li><font><font class="">如果需要几个参数，这些参数将以逗号分隔： </font></font><code>@{/order/process(execId=${execId},execType='FAST')}</code>
                    </li>
                    <li>
                        <font><font>URL路径中也允许使用变量模板： </font></font><code>@{/order/{orderId}/details(orderId=${orderId})}</code>
                    </li>
                    <li>
                        <font><font>以</font></font><code>/</code><font><font>（eg </font></font><code>/order/details</code><font><font>：）开头的</font><font>相对URL </font><font>将以应用程序上下文名称自动为前缀。</font></font>
                    </li>
                    <li><font><font>如果未启用Cookie，或者尚未知道Cookie，则</font></font><code>";jsessionid=..."</code><font><font>可能会将相应的URL添加到后缀，以便会话被保留。</font><font>这被称为</font></font><em><font><font>URL重写</font></font></em><font><font>，Thymeleaf允许您使用</font></font><code>response.encodeURL(...)</code><font><font>Servlet
                        API中针对每个URL </font><font>的机制来插入自己的重写过滤器</font><font>。</font></font></li>
                    <li>
                        <font><font>该</font></font><code>th:href</code><font><font>属性允许我们（可选地）</font></font><code>href</code><font><font>在我们的模板中</font><font>有一个工作的静态</font><font>属性，以便我们的模板链接可以直接打开直接用于原型开发时被浏览器导航。</font></font>
                    </li>
                </ul>
                <p>
                    <font><font>与消息syntax（</font></font><code>#{...}</code><font><font>）的情况一样，URL基数也可以是评估另一个表达式的结果：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>href</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>@{${url}(orderId<span class="token punctuation">=</span>${o.id})}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
        class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span>@{<span
        class="token punctuation">'</span>/details/<span class="token punctuation">'</span>+${user.login}(orderId<span
        class="token punctuation">=</span>${o.id})}<span class="token punctuation">"</span></span><span
        class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                <section class="level3" id="a-menu-for-our-home-page">
                    <h3><font><font>我们的主页菜单</font></font></h3>
                    <p><font><font>现在我们知道如何创建链接网址，如何在网站的其他一些页面的主页中添加一个小菜单呢？</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                            class="token punctuation">&gt;</span></span>Please select an option<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ol</span><span
        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span
          class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;</span>a</span> <span
                                class="token attr-name">href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span class="token punctuation">"</span>product/list.html<span
                                class="token punctuation">"</span></span> <span class="token attr-name"><span
                                class="token namespace">th:</span>href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span class="token punctuation">"</span>@{/product/list}<span
                                class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>Product List<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>a</span><span
                                class="token punctuation">&gt;</span></span><span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>li</span><span
                                class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span
          class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;</span>a</span> <span
                                class="token attr-name">href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span class="token punctuation">"</span>order/list.html<span
                                class="token punctuation">"</span></span> <span class="token attr-name"><span
                                class="token namespace">th:</span>href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span class="token punctuation">"</span>@{/order/list}<span
                                class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>Order List<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>a</span><span
                                class="token punctuation">&gt;</span></span><span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>li</span><span
                                class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span
          class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;</span>a</span> <span
                                class="token attr-name">href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span class="token punctuation">"</span>subscribe.html<span
                                class="token punctuation">"</span></span> <span class="token attr-name"><span
                                class="token namespace">th:</span>href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span
                                class="token punctuation">"</span>@{/subscribe}<span class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>Subscribe to our Newsletter<span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span
                                class="token punctuation">&gt;</span></span><span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>li</span><span
                                class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span
          class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;</span>a</span> <span
                                class="token attr-name">href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span class="token punctuation">"</span>userprofile.html<span
                                class="token punctuation">"</span></span> <span class="token attr-name"><span
                                class="token namespace">th:</span>href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span class="token punctuation">"</span>@{/userprofile}<span
                                class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>See User Profile<span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span
                                class="token punctuation">&gt;</span></span><span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>li</span><span
                                class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ol</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                </section>
                <section class="level3" id="server-root-relative-urls">
                    <h3><font><font>服务器根相对URL</font></font></h3>
                    <p><font><font>可以使用附加语法来创建服务器根目录（而不是上下文相对）URL，以链接到同一服务器中的不同上下文。</font><font>这些URL将被指定为</font></font><code>@{~/path/to/something}</code>
                    </p>
                </section>
            </section>
            <section class="level2" id="fragments">
                <h2><font><font>4.5片段</font></font></h2>
                <p><font><font>片段表达式是表示标记片段的简单方法，并将其移动到模板周围。</font><font>这允许我们复制它们，将它们传递给其他模板作为参数，等等。</font></font></p>
                <p>
                    <font><font>最常见的用途是使用</font></font><code>th:insert</code><font><font>或</font></font><code>th:replace</code><font><font>（更多的在以后的部分）</font><font>进行片段插入</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>insert</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>~{commons :: main}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>但它们可以在任何地方使用，就像任何其他变量一样：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>with</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>frag<span class="token punctuation">=</span>~{footer :: #main/text()}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
          class="token attr-name"><span class="token namespace">th:</span>insert</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${frag}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>在本教程的后面，有一个专门用于模板布局的部分，包括对片段表达式的更深入的解释。</font></font></p>
            </section>
            <section class="level2" id="literals">
                <h2><font><font>4.6文字</font></font></h2>
                <section class="level3" id="text-literals">
                    <h3><font><font>文字文字</font></font></h3>
                    <p>
                        <font><font>文本文字只是在单引号之间指定的字符串。</font><font>它们可以包含任何字符，但您应该使用它们内的任何单引号</font></font><code>\'</code><font><font>。</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  Now you are looking at a <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                                class="token attr-value"><span class="token punctuation">=</span><span
                                class="token punctuation">"</span><span class="token punctuation">'</span>working web application<span
                                class="token punctuation">'</span><span class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>template file<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                                class="token punctuation">&gt;</span></span>.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                </section>
                <section class="level3" id="number-literals">
                    <h3><font><font>数字字面值</font></font></h3>
                    <p><font><font>数字文字就是这样：数字。</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                            class="token punctuation">&gt;</span></span>The year is <span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>text</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>2013<span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span>1492<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                            class="token punctuation">&gt;</span></span>.<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
        class="token punctuation">&gt;</span></span>In two years, it will be <span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                                class="token attr-value"><span class="token punctuation">=</span><span
                                class="token punctuation">"</span>2013 + 2<span
                                class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>1494<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                                class="token punctuation">&gt;</span></span>.<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                                class="token punctuation">&gt;</span></span></code></pre>
                </section>
                <section class="level3" id="boolean-literals">
                    <h3><font><font>布尔文字</font></font></h3>
                    <p>
                        <font><font>布尔文字是</font></font><code>true</code><font><font>和</font></font><code>false</code><font><font>。</font><font>例如：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>if</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>${user.isAdmin()} <span class="token punctuation">=</span><span
                            class="token punctuation">=</span> false<span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span> ...</code></pre>
                    <p><font><font>在这个例子中，这</font></font><code>==
                        false</code><font><font>是写在大括号之外，所以它是Thymeleaf照顾它。</font><font>如果它是写在大括号内，那将是OGNL /
                        SpringEL引擎的责任：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>if</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>${user.isAdmin() <span
                            class="token punctuation">=</span><span class="token punctuation">=</span> false}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> ...</code></pre>
                </section>
                <section class="level3" id="the-null-literal">
                    <h3><font><font>无效文字</font></font></h3>
                    <p><font><font>该</font></font><code>null</code><font><font>文本也可用于：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>if</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>${variable.something} <span
                            class="token punctuation">=</span><span class="token punctuation">=</span> null<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> ...</code></pre>
                </section>
                <section class="level3" id="literal-tokens">
                    <h3><font><font>文字代币</font></font></h3>
                    <p>
                        <font><font>数字，布尔和空字面实际上是</font></font><em><font><font>字面令牌</font></font></em><font><font>的特殊情况</font><font>。</font></font>
                    </p>
                    <p>
                        <font><font>这些令牌允许在标准表达式中进行一点简化。</font><font>它们的工作与文本文字（</font></font><code>'...'</code><font><font>）</font><font>完全相同</font><font>，但它们只允许使用字母（</font></font><code>A-Z</code><font><font>和</font></font><code>a-z</code><font><font>），数字（</font></font><code>0-9</code><font><font>），括号（</font></font><code>[</code><font><font>和</font></font><code>]</code><font><font>），点（</font></font><code>.</code><font><font>），连字符（</font></font><code>-</code><font><font>）和下划线（</font></font><code>_</code><font><font>）。</font><font>所以没有空白，没有逗号等</font></font>
                    </p>
                    <p><font><font>好的部分？</font><font>令牌不需要围绕它们的任何引号。</font><font>所以我们可以这样做：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>class</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>content<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>代替：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>class</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span><span class="token punctuation">'</span>content<span
                            class="token punctuation">'</span><span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                </section>
            </section>
            <section class="level2" id="appending-texts">
                <h2><font><font>4.7附加文本</font></font></h2>
                <p><font><font>无论是文字，还是评估变量或消息表达式的结果，都可以使用</font></font><code>+</code><font><font>操作符</font><font>轻松地附加文本</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span><span class="token punctuation">'</span>The name of the user is <span
                        class="token punctuation">'</span> + ${user.name}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="literal-substitutions">
                <h2><font><font>4.8字面替代</font></font></h2>
                <p><font><font>字面替换允许容易地格式化包含变量值的字符串，而不需要附加文字</font></font><code>'...' +
                    '...'</code><font><font>。</font></font></p>
                <p>
                    <font><font>这些替换必须被垂直条（</font></font><code>|</code><font><font>）</font><font>包围</font><font>，如：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>|Welcome to our application, ${user.name}!|<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这相当于：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span><span class="token punctuation">'</span>Welcome to our application, <span
                        class="token punctuation">'</span> + ${user.name} + <span
                        class="token punctuation">'</span>!<span class="token punctuation">'</span><span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>文字替换可以与其他类型的表达式相结合：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${onevar} + <span class="token punctuation">'</span> <span
                        class="token punctuation">'</span> + |${twovar}, ${threevar}|<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <blockquote>
                    <p>
                        <font><font>唯一的变量/消息表达式（</font></font><code>${...}</code><font><font>，</font></font><code>*{...}</code><font><font>，</font></font><code>#{...}</code><font><font>）被允许内部</font></font><code>|...|</code><font><font>字面取代。</font><font>没有其他文字（</font></font><code>'...'</code><font><font>），布尔/数字令牌，条件表达式等。</font></font>
                    </p>
                </blockquote>
            </section>
            <section class="level2" id="arithmetic-operations">
                <h2><font><font>4.9算术运算</font></font></h2>
                <p>
                    <font><font>一些算术运算也可用：</font></font><code>+</code><font><font>，</font></font><code>-</code><font><font>，</font></font><code>*</code><font><font>，</font></font><code>/</code><font><font>和</font></font><code>%</code><font><font>。</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>with</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>isEven<span class="token punctuation">=</span>(${prodStat.count} % 2 <span
                        class="token punctuation">=</span><span class="token punctuation">=</span> 0)<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>请注意，这些运算符也可以在OGNL变量表达式本身中应用（在这种情况下将由OGNL执行，而不是Thymeleaf标准表达式引擎）：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>with</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>isEven<span class="token punctuation">=</span>${prodStat.count % 2 <span
                        class="token punctuation">=</span><span class="token punctuation">=</span> 0}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>请注意，其中一些运算符存在文本别名：</font></font><code>div</code><font><font>（</font></font><code>/</code><font><font>），</font></font><code>mod</code><font><font>（</font></font><code>%</code><font><font>）。</font></font>
                </p>
            </section>
            <section class="level2" id="comparators-and-equality">
                <h2><font><font>4.10比较与平等</font></font></h2>
                <p><font><font>在表达式中的值可以与进行比较</font></font><code>&gt;</code><font><font>，</font></font><code>&lt;</code><font><font>，</font></font><code>&gt;=</code><font><font>和</font></font><code>&lt;=</code><font><font>符号，以及</font></font><code>==</code><font><font>和</font></font><code>!=</code><font><font>运营商可以被用来检查是否相等（或缺乏）。</font><font>需要注意的是XML建立了</font></font><code>&lt;</code><font><font>和</font></font><code>&gt;</code><font><font>符号不应该在属性值被使用，并且因此他们应该被取代</font></font><code>&amp;lt;</code><font><font>和</font></font><code>&amp;gt;</code><font><font>。</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>if</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${prodStat.count} &amp;gt; 1<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
        class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span><span
        class="token punctuation">'</span>Execution mode is <span
        class="token punctuation">'</span> + ( (${execMode} <span class="token punctuation">=</span><span
        class="token punctuation">=</span> <span class="token punctuation">'</span>dev<span
        class="token punctuation">'</span>)? <span class="token punctuation">'</span>Development<span
        class="token punctuation">'</span> : <span class="token punctuation">'</span>Production<span
        class="token punctuation">'</span>)<span class="token punctuation">"</span></span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>一个更简单的选择可能是使用这些运算符中存在的文本别名：</font></font><code>gt</code><font><font>（</font></font><code>&gt;</code><font><font>），</font></font><code>lt</code><font><font>（</font></font><code>&lt;</code><font><font>），</font></font><code>ge</code><font><font>（</font></font><code>&gt;=</code><font><font>），</font></font><code>le</code><font><font>（</font></font><code>&lt;=</code><font><font>），</font></font><code>not</code><font><font>（</font></font><code>!</code><font><font>）。</font><font>还有</font></font><code>eq</code><font><font>（</font></font><code>==</code><font><font>），</font></font><code>neq</code><font><font>/ </font></font><code>ne</code><font><font>（</font></font><code>!=</code><font><font>）。</font></font>
                </p>
            </section>
            <section class="level2" id="conditional-expressions">
                <h2><font><font>4.11条件表达式</font></font></h2>
                <p>
                    <em><font><font>条件表达式</font></font></em><font><font>仅用于评估两个表达式中的一个，这取决于评估条件（本身就是另一个表达式）的结果。</font></font>
                </p>
                <p>
                    <font><font>让我们来看一个例子片段（引入另一个</font></font><em><font><font>属性修改器</font></font></em><font><font>，</font></font><code>th:class</code><font><font>）：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>class</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${row.even}? <span class="token punctuation">'</span>even<span
                        class="token punctuation">'</span> : <span class="token punctuation">'</span>odd<span
                        class="token punctuation">'</span><span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
  ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>条件表达式（</font></font><code>condition</code><font><font>，</font></font><code>then</code><font><font>和</font></font><code>else</code><font><font>）的</font><font>所有三个部分</font><font>都是表达式，这意味着它们可以是变量（</font></font><code>${...}</code><font><font>，</font></font><code>*{...}</code><font><font>），消息（</font></font><code>#{...}</code><font><font>），URL（</font></font><code>@{...}</code><font><font>）或文字（</font></font><code>'...'</code><font><font>））。</font></font>
                </p>
                <p><font><font>条件表达式也可以使用括号嵌套：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>class</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${row.even}? (${row.first}? <span
                        class="token punctuation">'</span>first<span class="token punctuation">'</span> : <span
                        class="token punctuation">'</span>even<span class="token punctuation">'</span>) : <span
                        class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
  ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>Else表达式也可以省略，在这种情况下，如果条件为false，则返回null值：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>class</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${row.even}? <span class="token punctuation">'</span>alt<span
                        class="token punctuation">'</span><span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
  ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="default-expressions-elvis-operator">
                <h2><font><font>4.12默认表达式（Elvis operator）</font></font></h2>
                <p>
                    <font><font>一个</font></font><em><font><font>默认的表情</font></font></em><font><font>是一种特殊的条件值的没有</font></font><em><font><font>那么</font></font></em><font><font>一部分。</font><font>它相当于以</font><font>一些语言（如Groovy）存在</font><font>的</font></font><em><font><font>Elvis操作员</font></font></em><font><font>，允许您指定两个表达式：如果不评估为null，则使用第一个表达式，但如果使用第二个表达式则使用第一个表达式。</font></font>
                </p>
                <p><font><font>让我们在我们的用户个人资料页面中看到它：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>object</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${session.user}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
  ...<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>Age: <span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                            class="token namespace">th:</span>text</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>*{age}?: <span
                            class="token punctuation">'</span>(no age specified)<span class="token punctuation">'</span><span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>27<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>.<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>正如你所看到的，操作符是</font></font><code>?:</code><font><font>，并且我们在这里使用它来指定名称的默认值（在这种情况下是字面值），只有当评估结果</font></font><code>*{age}</code><font><font>为空时。</font><font>这相当于：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>Age: <span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>*{age !<span class="token punctuation">=</span> null}? *{age} : <span
                        class="token punctuation">'</span>(no age specified)<span
                        class="token punctuation">'</span><span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>27<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>.<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>与条件值一样，它们可以在括号之间包含嵌套表达式：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span><font></font>
  Name: <font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
          class="token attr-name"><span class="token namespace">th:</span>text</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>*{firstName}?: (*{admin}? <span
          class="token punctuation">'</span>Admin<span class="token punctuation">'</span> : #{default.username})<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Sebastian<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="the-no-operation-token">
                <h2><font><font>4.13无操作令牌</font></font></h2>
                <p><font><font>无操作令牌由下划线符号（</font></font><code>_</code><font><font>）表示。</font></font></p>
                <p><font><font>这个标记背后的想法是指定一个表达式的期望结果是</font></font><em><font><font>什么也不做</font></font></em><font><font>，即完全像可执行的属性（eg </font></font><code>th:text</code><font><font>）根本不存在。</font></font>
                </p>
                <p><font><font>除了其他可能性之外，这允许开发人员使用原型文本作为默认值。</font><font>例如，而不是：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${user.name} ?: <span class="token punctuation">'</span>no user authenticated<span
                        class="token punctuation">'</span><span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>...我们可以直接使用</font></font><em><font><font>“没有用户认证”</font></font></em><font><font>作为原型设计文本，从而从设计的角度来看，这些代码更加简洁和多才多艺：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${user.name} ?: _<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>no user authenticated<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="data-conversion-formatting">
                <h2><font><font>4.15数据转换/格式化</font></font></h2>
                <p><font><font>Thymeleaf </font><font>为variable（</font><font>）和selection（</font><font>）</font><font>表达式定义了一个</font></font><em><font><font>双括号</font></font></em><font><font>语法</font><font>，允许我们</font><font>通过配置的</font><em><font>转换服务</font></em><font>应用</font><em><font>数据转换</font></em><font>。</font></font><code>${...}</code><font></font><code>*{...}</code><font></font><em><font></font></em><font></font><em><font></font></em><font></font>
                </p>
                <p><font><font>它基本上是这样的：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${{user.lastAccessDate}}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>注意到有双括号？： </font></font><code>${{...}}</code><font><font>。</font><font>这指示Thymeleaf将表达式的结果传递</font></font><code>user.lastAccessDate</code><font><font>给</font></font><em><font><font>转换服务</font></font></em><font><font>，并要求它</font><font>在写入结果之前</font><font>执行</font></font><strong><font><font>格式化操作</font></font></strong><font><font>（转换为</font></font><code>String</code><font><font>）。</font></font>
                </p>
                <p><font><font>假设</font></font><code>user.lastAccessDate</code><font><font>是类型的</font></font><code>java.util.Calendar</code><font><font>，如果</font><font>已经注册</font><font>了</font></font><em><font><font>转换服务</font></font></em><font><font>（实现</font></font><code>IStandardConversionService</code><font><font>）并且包含有效的转换</font></font><code>Calendar
                    -&gt; String</code><font><font>，则它将被应用。</font></font></p>
                <p><font></font><code>IStandardConversionService</code><font><font>（</font></font><code>StandardConversionService</code><font><font>类）</font><font>的默认实现</font><font>只是</font></font><code>.toString()</code><font><font>在转换为的任何对象上</font><font>执行</font></font><code>String</code><font><font>。</font><font>有关如何注册自定义</font></font><em><font><font>转换服务</font></font></em><font><font>实现的</font></font><a
                        href="#more-on-configuration"><font><font>更多信息，请</font></font></a><font><font>参阅</font><a
                        href="#more-on-configuration"><font>更多配置</font></a><font>部分。</font></font></p>
                <blockquote>
                    <p>
                        <font><font>官方thymeleaf-spring3和thymeleaf-spring4集成软件包的透明集成了Spring自己Thymeleaf的转换服务机制</font></font><em><font><font>转换服务</font></font></em><font><font>的基础设施，所以在Spring配置宣称，转换服务和格式化将进行自动获得</font></font><code>${{...}}</code><font><font>和</font></font><code>*{{...}}</code><font><font>表达。</font></font>
                    </p>
                </blockquote>
            </section>
            <section class="level2" id="preprocessing">
                <h2><font><font>4.14预处理</font></font></h2>
                <p>
                    <font><font>除了表达式处理的所有这些功能之外，Thymeleaf具有</font></font><em><font><font>预处理</font></font></em><font><font>表达式</font><font>的功能</font><font>。</font></font>
                </p>
                <p><font><font>预处理是在正常的表达式之前执行的表达式的执行，允许修改最终将被执行的表达式。</font></font></p>
                <p>
                    <font><font>预处理的表达式与正常表达式完全相同，但是由双下划线符号（如</font></font><code>__${expression}__</code><font><font>）所示。</font></font>
                </p>
                <p>
                    <font><font>让我们想象一下，我们有一个</font></font><code>Messages_fr.properties</code><font><font>包含一个OGNL表达式</font><font>的i18n </font><font>表达式，调用一个特定于语言的静态方法，如：</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java">article<span
                        class="token punctuation">.</span>text<span class="token operator">=</span>@myapp<span
                        class="token punctuation">.</span>translator<span
                        class="token punctuation">.</span>Translator@<span
                        class="token function">translateToFrench</span><span class="token punctuation">(</span><span
                        class="token punctuation">{</span><span class="token number">0</span><span
                        class="token punctuation">}</span><span class="token punctuation">)</span></code></pre>
                <p><font><font>...和a </font></font><code>Messages_es.properties
                    equivalent</code><font><font>：</font></font></p>
                <pre class="  language-java"><code class="  language-java">article<span
                        class="token punctuation">.</span>text<span class="token operator">=</span>@myapp<span
                        class="token punctuation">.</span>translator<span
                        class="token punctuation">.</span>Translator@<span
                        class="token function">translateToSpanish</span><span class="token punctuation">(</span><span
                        class="token punctuation">{</span><span class="token number">0</span><span
                        class="token punctuation">}</span><span class="token punctuation">)</span></code></pre>
                <p>
                    <font><font>我们可以创建一个标记片段，根据语言环境来评估一个表达式或另一个表达式。</font><font>为此，我们首先选择表达式（通过预处理），然后让Thymeleaf执行它：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${__#{article.text(<span class="token punctuation">'</span>textVar<span
                        class="token punctuation">'</span>)}__}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>Some text here...<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>请注意，法语区域设置的预处理步骤将创建以下等效项：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${@myapp.translator.Translator@translateToFrench(textVar)}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Some text here...<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>预处理字符串</font></font><code>__</code><font><font>可以使用</font><font>属性</font><font>进行转义</font></font><code>\_\_</code><font><font>。</font></font>
                </p>
            </section>
        </section>
        <section class="level1" id="setting-attribute-values">
            <h1><font><font>5设置属性值</font></font></h1>
            <p><font><font>本章将介绍我们在标记中设置（或修改）属性值的方式。</font></font></p>
            <section class="level2" id="setting-the-value-of-any-attribute">
                <h2><font><font>5.1设置任何属性的值</font></font></h2>
                <p>
                    <font><font>说我们的网站发布通讯，我们希望用户能够订阅，所以我们创建</font></font><code>/WEB-INF/templates/subscribe.html</code><font><font>一个表单</font><font>的</font><font>模板：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>form</span> <span
                        class="token attr-name">action</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>subscribe.html<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>fieldset</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
            class="token attr-name">type</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>text<span
            class="token punctuation">"</span></span> <span class="token attr-name">name</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>email<span
            class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
            class="token attr-name">type</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>submit<span
            class="token punctuation">"</span></span> <span class="token attr-name">value</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Subscribe!<span
            class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>fieldset</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>form</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>与Thymeleaf一样，这个模板比一个Web应用程序的模板更像是一个静态原型。</font><font>首先，</font></font><code>action</code><font><font>我们表单中的属性静态地链接到模板文件本身，这样就没有可用的URL重写的地方。</font><font>其次，</font></font><code>value</code><font><font>提交按钮中的属性使其显示英文文本，但我们希望将其国际化。</font></font>
                </p>
                <p><font><font>输入</font></font><code>th:attr</code><font><font>属性，并</font><font>输入</font><font>其中设置的变量的属性值的能力：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>form</span> <span
                        class="token attr-name">action</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>subscribe.html<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>attr</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>action<span
                        class="token punctuation">=</span>@{/subscribe}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>fieldset</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
            class="token attr-name">type</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>text<span
            class="token punctuation">"</span></span> <span class="token attr-name">name</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>email<span
            class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
            class="token attr-name">type</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>submit<span
            class="token punctuation">"</span></span> <span class="token attr-name">value</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Subscribe!<span
            class="token punctuation">"</span></span> <span class="token attr-name"><span
            class="token namespace">th:</span>attr</span><span class="token attr-value"><span class="token punctuation">=</span><span
            class="token punctuation">"</span>value<span class="token punctuation">=</span>#{subscribe.submit}<span
            class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>fieldset</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>form</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这个概念很简单：</font></font><code>th:attr</code><font><font>只需要一个赋值给一个属性的表达式。</font><font>创建相应的控制器和消息文件后，处理此文件的结果将是：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>form</span> <span
                        class="token attr-name">action</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>/gtvg/subscribe<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>fieldset</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
            class="token attr-name">type</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>text<span
            class="token punctuation">"</span></span> <span class="token attr-name">name</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>email<span
            class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
            class="token attr-name">type</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>submit<span
            class="token punctuation">"</span></span> <span class="token attr-name">value</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>¡Suscríbe!<span
            class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>fieldset</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>form</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>除了新的属性值之外，您还可以看到，应用上下文名称已经自动前缀到URL基础中</font></font><code>/gtvg/subscribe</code><font><font>，如前一章所述。</font></font>
                </p>
                <p>
                    <font><font>但是如果我们想要一次设置多个属性呢？</font><font>XML规则不允许您在标签中设置两次属性，因此</font></font><code>th:attr</code><font><font>将以逗号分隔的分配列表，如：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>img</span> <span
                        class="token attr-name">src</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>../../images/gtvglogo.png<span
                        class="token punctuation">"</span></span>
     <span class="token attr-name"><span class="token namespace">th:</span>attr</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>src<span class="token punctuation">=</span>@{/images/gtvglogo.png},title<span
                            class="token punctuation">=</span>#{logo},alt<span class="token punctuation">=</span>#{logo}<span
                            class="token punctuation">"</span></span> <span
                            class="token punctuation">/&gt;</span></span></code></pre>
                <p><font><font>给定所需的消息文件，这将输出：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>img</span> <span
                        class="token attr-name">src</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>/gtgv/images/gtvglogo.png<span
                        class="token punctuation">"</span></span> <span class="token attr-name">title</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>Logo de Good Thymes<span
                        class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>Logo de Good Thymes<span
                        class="token punctuation">"</span></span> <span
                        class="token punctuation">/&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="setting-value-to-specific-attributes">
                <h2><font><font>5.2将值设置为特定属性</font></font></h2>
                <p><font><font>现在，你可能会想到像：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
                        class="token attr-name">type</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>submit<span
                        class="token punctuation">"</span></span> <span class="token attr-name">value</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>Subscribe!<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>attr</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>value<span
                        class="token punctuation">=</span>#{subscribe.submit}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">/&gt;</span></span></code></pre>
                <p><font><font>...是一个相当丑陋的标记。</font><font>在属性值内指定赋值可能非常实用，但如果您必须一直执行，则不是最优雅的创建模板的方式。</font></font></p>
                <p><font><font>Thymeleaf同意你的看法，这就是为什么</font></font><code>th:attr</code><font><font>几乎不用于模板。</font><font>通常，您将使用其他</font></font><code>th:*</code><font><font>属性，其任务是设置特定的标记属性（而不仅仅是任何属性</font></font><code>th:attr</code><font><font>）。</font></font>
                </p>
                <p>
                    <font><font>例如，要设置</font></font><code>value</code><font><font>属性，请使用</font></font><code>th:value</code><font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
                        class="token attr-name">type</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>submit<span
                        class="token punctuation">"</span></span> <span class="token attr-name">value</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>Subscribe!<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>value</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span
                        class="token punctuation">"</span>#{subscribe.submit}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">/&gt;</span></span></code></pre>
                <p>
                    <font><font>看起来好多了！</font><font>让我们尝试</font></font><code>action</code><font><font>对</font></font><code>form</code><font><font>标签</font><font>中的</font><font>属性</font><font>执行相同操作</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>form</span> <span
                        class="token attr-name">action</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>subscribe.html<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>action</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>@{/subscribe}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>你还记得</font></font><code>th:href</code><font><font>我们</font></font><code>home.html</code><font><font>以前的</font><font>那些</font><font>吗？</font><font>他们是同样的属性：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>li</span><span
                        class="token punctuation">&gt;</span></span><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                        class="token attr-name">href</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>product/list.html<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>href</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>@{/product/list}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Product List<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span><span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>li</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这些属性有很多属性，每个都针对特定的HTML5属性：</font></font></p>
                <div class="table-scroller">
                    <table>
                        <tbody>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:abbr</code></td>
                            <td style="text-align: left;"><code>th:accept</code></td>
                            <td style="text-align: left;"><code>th:accept-charset</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:accesskey</code></td>
                            <td style="text-align: left;"><code>th:action</code></td>
                            <td style="text-align: left;"><code>th:align</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:alt</code></td>
                            <td style="text-align: left;"><code>th:archive</code></td>
                            <td style="text-align: left;"><code>th:audio</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:autocomplete</code></td>
                            <td style="text-align: left;"><code>th:axis</code></td>
                            <td style="text-align: left;"><code>th:background</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:bgcolor</code></td>
                            <td style="text-align: left;"><code>th:border</code></td>
                            <td style="text-align: left;"><code>th:cellpadding</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:cellspacing</code></td>
                            <td style="text-align: left;"><code>th:challenge</code></td>
                            <td style="text-align: left;"><code>th:charset</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:cite</code></td>
                            <td style="text-align: left;"><code>th:class</code></td>
                            <td style="text-align: left;"><code>th:classid</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:codebase</code></td>
                            <td style="text-align: left;"><code>th:codetype</code></td>
                            <td style="text-align: left;"><code>th:cols</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:colspan</code></td>
                            <td style="text-align: left;"><code>th:compact</code></td>
                            <td style="text-align: left;"><code>th:content</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:contenteditable</code></td>
                            <td style="text-align: left;"><code>th:contextmenu</code></td>
                            <td style="text-align: left;"><code>th:data</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:datetime</code></td>
                            <td style="text-align: left;"><code>th:dir</code></td>
                            <td style="text-align: left;"><code>th:draggable</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:dropzone</code></td>
                            <td style="text-align: left;"><code>th:enctype</code></td>
                            <td style="text-align: left;"><code>th:for</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:form</code></td>
                            <td style="text-align: left;"><code>th:formaction</code></td>
                            <td style="text-align: left;"><code>th:formenctype</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:formmethod</code></td>
                            <td style="text-align: left;"><code>th:formtarget</code></td>
                            <td style="text-align: left;"><code>th:fragment</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:frame</code></td>
                            <td style="text-align: left;"><code>th:frameborder</code></td>
                            <td style="text-align: left;"><code>th:headers</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:height</code></td>
                            <td style="text-align: left;"><code>th:high</code></td>
                            <td style="text-align: left;"><code>th:href</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:hreflang</code></td>
                            <td style="text-align: left;"><code>th:hspace</code></td>
                            <td style="text-align: left;"><code>th:http-equiv</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:icon</code></td>
                            <td style="text-align: left;"><code>th:id</code></td>
                            <td style="text-align: left;"><code>th:inline</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:keytype</code></td>
                            <td style="text-align: left;"><code>th:kind</code></td>
                            <td style="text-align: left;"><code>th:label</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:lang</code></td>
                            <td style="text-align: left;"><code>th:list</code></td>
                            <td style="text-align: left;"><code>th:longdesc</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:low</code></td>
                            <td style="text-align: left;"><code>th:manifest</code></td>
                            <td style="text-align: left;"><code>th:marginheight</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:marginwidth</code></td>
                            <td style="text-align: left;"><code>th:max</code></td>
                            <td style="text-align: left;"><code>th:maxlength</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:media</code></td>
                            <td style="text-align: left;"><code>th:method</code></td>
                            <td style="text-align: left;"><code>th:min</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:name</code></td>
                            <td style="text-align: left;"><code>th:onabort</code></td>
                            <td style="text-align: left;"><code>th:onafterprint</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onbeforeprint</code></td>
                            <td style="text-align: left;"><code>th:onbeforeunload</code></td>
                            <td style="text-align: left;"><code>th:onblur</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:oncanplay</code></td>
                            <td style="text-align: left;"><code>th:oncanplaythrough</code></td>
                            <td style="text-align: left;"><code>th:onchange</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onclick</code></td>
                            <td style="text-align: left;"><code>th:oncontextmenu</code></td>
                            <td style="text-align: left;"><code>th:ondblclick</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:ondrag</code></td>
                            <td style="text-align: left;"><code>th:ondragend</code></td>
                            <td style="text-align: left;"><code>th:ondragenter</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:ondragleave</code></td>
                            <td style="text-align: left;"><code>th:ondragover</code></td>
                            <td style="text-align: left;"><code>th:ondragstart</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:ondrop</code></td>
                            <td style="text-align: left;"><code>th:ondurationchange</code></td>
                            <td style="text-align: left;"><code>th:onemptied</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onended</code></td>
                            <td style="text-align: left;"><code>th:onerror</code></td>
                            <td style="text-align: left;"><code>th:onfocus</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:onformchange</code></td>
                            <td style="text-align: left;"><code>th:onforminput</code></td>
                            <td style="text-align: left;"><code>th:onhashchange</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:oninput</code></td>
                            <td style="text-align: left;"><code>th:oninvalid</code></td>
                            <td style="text-align: left;"><code>th:onkeydown</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:onkeypress</code></td>
                            <td style="text-align: left;"><code>th:onkeyup</code></td>
                            <td style="text-align: left;"><code>th:onload</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onloadeddata</code></td>
                            <td style="text-align: left;"><code>th:onloadedmetadata</code></td>
                            <td style="text-align: left;"><code>th:onloadstart</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:onmessage</code></td>
                            <td style="text-align: left;"><code>th:onmousedown</code></td>
                            <td style="text-align: left;"><code>th:onmousemove</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onmouseout</code></td>
                            <td style="text-align: left;"><code>th:onmouseover</code></td>
                            <td style="text-align: left;"><code>th:onmouseup</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:onmousewheel</code></td>
                            <td style="text-align: left;"><code>th:onoffline</code></td>
                            <td style="text-align: left;"><code>th:ononline</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onpause</code></td>
                            <td style="text-align: left;"><code>th:onplay</code></td>
                            <td style="text-align: left;"><code>th:onplaying</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:onpopstate</code></td>
                            <td style="text-align: left;"><code>th:onprogress</code></td>
                            <td style="text-align: left;"><code>th:onratechange</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onreadystatechange</code></td>
                            <td style="text-align: left;"><code>th:onredo</code></td>
                            <td style="text-align: left;"><code>th:onreset</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:onresize</code></td>
                            <td style="text-align: left;"><code>th:onscroll</code></td>
                            <td style="text-align: left;"><code>th:onseeked</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onseeking</code></td>
                            <td style="text-align: left;"><code>th:onselect</code></td>
                            <td style="text-align: left;"><code>th:onshow</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:onstalled</code></td>
                            <td style="text-align: left;"><code>th:onstorage</code></td>
                            <td style="text-align: left;"><code>th:onsubmit</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:onsuspend</code></td>
                            <td style="text-align: left;"><code>th:ontimeupdate</code></td>
                            <td style="text-align: left;"><code>th:onundo</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:onunload</code></td>
                            <td style="text-align: left;"><code>th:onvolumechange</code></td>
                            <td style="text-align: left;"><code>th:onwaiting</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:optimum</code></td>
                            <td style="text-align: left;"><code>th:pattern</code></td>
                            <td style="text-align: left;"><code>th:placeholder</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:poster</code></td>
                            <td style="text-align: left;"><code>th:preload</code></td>
                            <td style="text-align: left;"><code>th:radiogroup</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:rel</code></td>
                            <td style="text-align: left;"><code>th:rev</code></td>
                            <td style="text-align: left;"><code>th:rows</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:rowspan</code></td>
                            <td style="text-align: left;"><code>th:rules</code></td>
                            <td style="text-align: left;"><code>th:sandbox</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:scheme</code></td>
                            <td style="text-align: left;"><code>th:scope</code></td>
                            <td style="text-align: left;"><code>th:scrolling</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:size</code></td>
                            <td style="text-align: left;"><code>th:sizes</code></td>
                            <td style="text-align: left;"><code>th:span</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:spellcheck</code></td>
                            <td style="text-align: left;"><code>th:src</code></td>
                            <td style="text-align: left;"><code>th:srclang</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:standby</code></td>
                            <td style="text-align: left;"><code>th:start</code></td>
                            <td style="text-align: left;"><code>th:step</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:style</code></td>
                            <td style="text-align: left;"><code>th:summary</code></td>
                            <td style="text-align: left;"><code>th:tabindex</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:target</code></td>
                            <td style="text-align: left;"><code>th:title</code></td>
                            <td style="text-align: left;"><code>th:type</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:usemap</code></td>
                            <td style="text-align: left;"><code>th:value</code></td>
                            <td style="text-align: left;"><code>th:valuetype</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:vspace</code></td>
                            <td style="text-align: left;"><code>th:width</code></td>
                            <td style="text-align: left;"><code>th:wrap</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:xmlbase</code></td>
                            <td style="text-align: left;"><code>th:xmllang</code></td>
                            <td style="text-align: left;"><code>th:xmlspace</code></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </section>
            <section class="level2" id="setting-more-than-one-value-at-a-time">
                <h2><font><font>5.3一次设置多个值</font></font></h2>
                <p><font><font>有两个叫比较特殊的属性</font></font><code>th:alt-title</code><font><font>和</font></font><code>th:lang-xmllang</code><font><font>可用于同时设置两个属性相同的值。</font><font>特别：</font></font>
                </p>
                <ul>
                    <li>
                        <code>th:alt-title</code><font><font>将设置</font></font><code>alt</code><font><font>和</font></font><code>title</code><font><font>。</font></font>
                    </li>
                    <li>
                        <code>th:lang-xmllang</code><font><font>将设置</font></font><code>lang</code><font><font>和</font></font><code>xml:lang</code><font><font>。</font></font>
                    </li>
                </ul>
                <p><font><font>对于我们的GTVG主页，这将允许我们用以下代替：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>img</span> <span
                        class="token attr-name">src</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>../../images/gtvglogo.png<span
                        class="token punctuation">"</span></span>
     <span class="token attr-name"><span class="token namespace">th:</span>attr</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>src<span class="token punctuation">=</span>@{/images/gtvglogo.png},title<span
                            class="token punctuation">=</span>#{logo},alt<span class="token punctuation">=</span>#{logo}<span
                            class="token punctuation">"</span></span> <span
                            class="token punctuation">/&gt;</span></span></code></pre>
                <p><font><font>...或者这个，相当于：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>img</span> <span
                        class="token attr-name">src</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>../../images/gtvglogo.png<span
                        class="token punctuation">"</span></span>
     <span class="token attr-name"><span class="token namespace">th:</span>src</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>@{/images/gtvglogo.png}<span
                            class="token punctuation">"</span></span> <span class="token attr-name"><span
                            class="token namespace">th:</span>title</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>#{logo}<span
                            class="token punctuation">"</span></span> <span class="token attr-name"><span
                            class="token namespace">th:</span>alt</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>#{logo}<span
                            class="token punctuation">"</span></span> <span
                            class="token punctuation">/&gt;</span></span></code></pre>
                <p><font><font>…有了这个：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>img</span> <span
                        class="token attr-name">src</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>../../images/gtvglogo.png<span
                        class="token punctuation">"</span></span>
     <span class="token attr-name"><span class="token namespace">th:</span>src</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>@{/images/gtvglogo.png}<span
                            class="token punctuation">"</span></span> <span class="token attr-name"><span
                            class="token namespace">th:</span>alt-title</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>#{logo}<span
                            class="token punctuation">"</span></span> <span
                            class="token punctuation">/&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="appending-and-prepending">
                <h2><font><font>5.4附加和前缀</font></font></h2>
                <p><font><font>Thymeleaf还提供</font></font><code>th:attrappend</code><font><font>和</font></font><code>th:attrprepend</code><font><font>属性，其中追加（后缀）或预先准备（前缀）的评估，以现有的属性值的结果。</font></font>
                </p>
                <p><font><font>例如，您可能想要将要添加的CSS类的名称（未设置，刚添加）存储在上下文变量的其中一个按钮中，因为要使用的特定CSS类将取决于用户所做的某些操作之前：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
                        class="token attr-name">type</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>button<span
                        class="token punctuation">"</span></span> <span class="token attr-name">value</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>Do it!<span class="token punctuation">"</span></span> <span
                        class="token attr-name">class</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>btn<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>attrappend</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>class<span
                        class="token punctuation">=</span>${<span class="token punctuation">'</span> <span
                        class="token punctuation">'</span> + cssStyle}<span
                        class="token punctuation">"</span></span> <span
                        class="token punctuation">/&gt;</span></span></code></pre>
                <p>
                    <font><font>如果处理此模板的</font></font><code>cssStyle</code><font><font>变量设置为</font></font><code>"warning"</code><font><font>，您将得到：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
                        class="token attr-name">type</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>button<span
                        class="token punctuation">"</span></span> <span class="token attr-name">value</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>Do it!<span class="token punctuation">"</span></span> <span
                        class="token attr-name">class</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>btn warning<span
                        class="token punctuation">"</span></span> <span
                        class="token punctuation">/&gt;</span></span></code></pre>
                <p>
                    <font><font>还有两个特定</font></font><em><font><font>追加属性</font></font></em><font><font>在标准方言：在</font></font><code>th:classappend</code><font><font>和</font></font><code>th:styleappend</code><font><font>属性，其用于添加CSS类或片段</font></font><em><font><font>风格</font></font></em><font><font>的元素，但不覆盖现有的：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>each</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>prod : ${prods}<span class="token punctuation">"</span></span> <span
                        class="token attr-name">class</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>row<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>classappend</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>${prodStat.odd}? <span
                        class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>（不要担心这个</font></font><code>th:each</code><font><font>属性，它是一个</font></font><em><font><font>迭代的属性</font></font></em><font><font>，我们稍后再讨论一下）</font></font>
                </p>
            </section>
            <section class="level2" id="fixed-value-boolean-attributes">
                <h2><font><font>5.5固定值布尔属性</font></font></h2>
                <p><font><font>HTML具有</font></font><em><font><font>布尔属性</font></font></em><font><font>的概念，</font><font>没有值的属性，并且一个的假设意味着该值为“true”。</font><font>在XHTML中，这些属性只取一个值，它本身就是。</font></font>
                </p>
                <p><font><font>例如</font></font><code>checked</code><font><font>：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
                        class="token attr-name">type</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>checkbox<span
                        class="token punctuation">"</span></span> <span class="token attr-name">name</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>option2<span class="token punctuation">"</span></span> <span
                        class="token attr-name">checked</span> <span class="token punctuation">/&gt;</span></span> <span
                        class="token comment" spellcheck="true">&lt;!-- HTML --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
        class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span
        class="token punctuation">"</span>checkbox<span class="token punctuation">"</span></span> <span
        class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span
        class="token punctuation">"</span>option1<span class="token punctuation">"</span></span> <span
        class="token attr-name">checked</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span>checked<span
        class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span> <span
                            class="token comment" spellcheck="true">&lt;!-- XHTML --&gt;</span></code></pre>
                <p><font><font>标准方言包括允许您通过评估条件设置这些属性的属性，以便如果评估为true，则该属性将被设置为其固定值，如果评估为false，则不会设置该属性：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>input</span> <span
                        class="token attr-name">type</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>checkbox<span
                        class="token punctuation">"</span></span> <span class="token attr-name">name</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>active<span class="token punctuation">"</span></span> <span
                        class="token attr-name"><span class="token namespace">th:</span>checked</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${user.active}<span class="token punctuation">"</span></span> <span
                        class="token punctuation">/&gt;</span></span></code></pre>
                <p><font><font>标准方言中存在以下固定值布尔属性：</font></font></p>
                <div class="table-scroller">
                    <table>
                        <tbody>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:async</code></td>
                            <td style="text-align: left;"><code>th:autofocus</code></td>
                            <td style="text-align: left;"><code>th:autoplay</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:checked</code></td>
                            <td style="text-align: left;"><code>th:controls</code></td>
                            <td style="text-align: left;"><code>th:declare</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:default</code></td>
                            <td style="text-align: left;"><code>th:defer</code></td>
                            <td style="text-align: left;"><code>th:disabled</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:formnovalidate</code></td>
                            <td style="text-align: left;"><code>th:hidden</code></td>
                            <td style="text-align: left;"><code>th:ismap</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:loop</code></td>
                            <td style="text-align: left;"><code>th:multiple</code></td>
                            <td style="text-align: left;"><code>th:novalidate</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:nowrap</code></td>
                            <td style="text-align: left;"><code>th:open</code></td>
                            <td style="text-align: left;"><code>th:pubdate</code></td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: left;"><code>th:readonly</code></td>
                            <td style="text-align: left;"><code>th:required</code></td>
                            <td style="text-align: left;"><code>th:reversed</code></td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: left;"><code>th:scoped</code></td>
                            <td style="text-align: left;"><code>th:seamless</code></td>
                            <td style="text-align: left;"><code>th:selected</code></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </section>
            <section class="level2" id="setting-the-value-of-any-attribute-default-attribute-processor">
                <h2><font><font>5.6设置任意属性的值（默认属性处理器）</font></font></h2>
                <p>
                    <font><font>Thymeleaf提供了一个</font></font><em><font><font>默认属性处理器</font></font></em><font><font>，允许我们设置</font></font><em><font><font>任何</font></font></em><font><font>属性</font><font>的值</font><font>，即使</font></font><code>th:*</code><font><font>在标准方言中</font><font>没有</font><font>为其定义</font><font>特定的</font><font>处理器。</font></font>
                </p>
                <p><font><font>所以这样的东西：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>whatever</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${user.name}<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>将导致：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name">whatever</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>John Apricot<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="support-for-html5-friendly-attribute-and-element-names">
                <h2><font><font>5.7支持HTML5友好的属性和元素名称</font></font></h2>
                <p><font><font>也可以使用完全不同的语法来以更友好的HTML5方式将处理器应用于您的模板。</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
            class="token attr-name">data-th-each</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>user : ${users}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">data-th-text</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>${user.login}<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">data-th-text</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>${user.name}<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>该</font></font><code>data-{prefix}-{name}</code><font><font>语法编写自定义属性在HTML5中，而无需开发人员使用任何命名空间的名称，如标准的方式</font></font><code>th:*</code><font><font>。</font><font>Thymeleaf使这种语法自动提供给所有的方言（不仅仅是标准的）。</font></font>
                </p>
                <p>
                    <font><font>还有一种语法来指定自定义标签：</font></font><code>{prefix}-{name}</code><font><font>它遵循</font></font><em><font><font>W3C自定义元素规范</font></font></em><font><font>（较大的</font></font><em><font><font>W3C
                    Web Components规范的一部分</font></font></em><font><font>）。</font><font>这可以用于例如</font></font><code>th:block</code><font><font>元素（或者</font></font><code>th-block</code><font><font>），这将在后面的部分中解释。</font></font>
                </p>
                <p>
                    <strong><font><font>重要提示：</font></font></strong><font><font>此语法是除命名空间之外的</font></font><code>th:*</code><font><font>一种，它不会替代它。</font><font>在将来，根本就不用放弃命名空间的语法。</font></font>
                </p>
            </section>
        </section>
        <section class="level1" id="iteration">
            <h1><font><font>6迭代</font></font></h1>
            <p><font><font>到目前为止，我们已经创建了一个主页，一个用户个人资料页面，还有一个页面，让用户订阅我们的通讯...但是我们的产品呢？</font><font>为此，我们需要一种迭代集合中的项目来构建我们的产品页面。</font></font>
            </p>
            <section class="level2" id="iteration-basics">
                <h2><font><font>6.1迭代基础</font></font></h2>
                <p><font><font>要在我们的</font></font><code>/WEB-INF/templates/product/list.html</code><font><font>页面</font><font>中显示产品，</font><font>我们将使用表格。</font><font>我们的每个产品将被显示在一行（一个</font></font><code>&lt;tr&gt;</code><font><font>元素）中，因此对于我们的模板，我们将需要创建一个</font></font><em><font><font>模板行</font></font></em><font><font>
                    - 这将会展示我们想要显示每个产品的方式，然后指示Thymeleaf重复，每次产品一次</font></font></p>
                <p><font><font>标准方言为我们提供了整整一个属性：</font></font><code>th:each</code><font><font>。</font></font></p>
                <section class="level3" id="using-theach">
                    <h3><font><font>使用th：each</font></font></h3>
                    <p><font><font>对于我们的产品列表页面，我们将需要一个控制器方法，从服务层检索产品列表，并将其添加到模板上下文中：</font></font></p>
                    <pre class="  language-java"><code class="  language-java"><span class="token keyword">public</span> <span
                            class="token keyword">void</span> <span class="token function">process</span><span
                            class="token punctuation">(</span>
        <span class="token keyword">final</span> HttpServletRequest request<span
                                class="token punctuation">,</span> <span class="token keyword">final</span> HttpServletResponse response<span
                                class="token punctuation">,</span>
        <span class="token keyword">final</span> ServletContext servletContext<span
                                class="token punctuation">,</span> <span class="token keyword">final</span> ITemplateEngine templateEngine<span
                                class="token punctuation">)</span>
        <span class="token keyword">throws</span> Exception <span class="token punctuation">{</span><font></font>
    <font></font>
    ProductService productService <span class="token operator">=</span> <span class="token keyword">new</span> <span
                                class="token class-name">ProductService</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    List<span class="token operator">&lt;</span>Product<span class="token operator">&gt;</span> allProducts <span
                                class="token operator">=</span> productService<span
                                class="token punctuation">.</span><span class="token function">findAll</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span> <font></font>
    <font></font>
    WebContext ctx <span class="token operator">=</span> <span class="token keyword">new</span> <span
                                class="token class-name">WebContext</span><span class="token punctuation">(</span>request<span
                                class="token punctuation">,</span> response<span class="token punctuation">,</span> servletContext<span
                                class="token punctuation">,</span> request<span class="token punctuation">.</span><span
                                class="token function">getLocale</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
    ctx<span class="token punctuation">.</span><span class="token function">setVariable</span><span
                                class="token punctuation">(</span><span class="token string">"prods"</span><span
                                class="token punctuation">,</span> allProducts<span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
    <font></font>
    templateEngine<span class="token punctuation">.</span><span class="token function">process</span><span
                                class="token punctuation">(</span><span class="token string">"product/list"</span><span
                                class="token punctuation">,</span> ctx<span
                                class="token punctuation">,</span> response<span class="token punctuation">.</span><span
                                class="token function">getWriter</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">)</span><span
                                class="token punctuation">;</span><font></font>
    <font></font>
<span class="token punctuation">}</span></code></pre>
                    <p><font><font>然后我们将使用</font></font><code>th:each</code><font><font>我们的模板来迭代产品列表：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span
        class="token attr-name"><span class="token namespace">xmlns:</span>th</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span><a href="http://www.thymeleaf.org"
                                                                                     rel="noreferrer"
                                                                                     style="cursor:help;display:inline !important;"
                                                                                     target="_blank">http://www.thymeleaf.org</a><span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
            class="token punctuation">&gt;</span></span>Good Thymes Virtual Grocery<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                                class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span
            class="token attr-name">http-equiv</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>Content-Type<span
            class="token punctuation">"</span></span> <span class="token attr-name">content</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/html; charset<span
            class="token punctuation">=</span>UTF-8<span class="token punctuation">"</span></span> <span
            class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
            class="token attr-name">rel</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>stylesheet<span
            class="token punctuation">"</span></span> <span class="token attr-name">type</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
            class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all<span
            class="token punctuation">"</span></span>
          <span class="token attr-name">href</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>../../../css/gtvg.css<span
                class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>@{/css/gtvg.css}<span class="token punctuation">"</span></span> <span
                class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span
            class="token punctuation">&gt;</span></span>Product list<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span
                                class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;/</span>th</span><span
                                class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;/</span>th</span><span
                                class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>th</span><span
                                class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
              class="token attr-name"><span class="token namespace">th:</span>each</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>prod : ${prods}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${prod.name}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>Onions<span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;/</span>td</span><span
                                class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${prod.price}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>2.41<span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;/</span>td</span><span
                                class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${prod.inStock}? #{true} : #{false}<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>yes<span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                                class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>../home.html<span class="token punctuation">"</span></span> <span
              class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>@{/}<span
              class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>Return to home<span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;/</span>a</span><span
                                class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>也就是说</font></font><code>prod :
                        ${prods}</code><font><font>您在上面看到的属性值是指“用于评估的结果的每个元素</font></font><code>${prods}</code><font><font>，重复模板的该片段，用在变量称为刺当前元素”。</font><font>让我们给每个我们看到的东西一个名字：</font></font>
                    </p>
                    <ul>
                        <li>
                            <font><font>我们将调用</font></font><code>${prods}</code><font><font>的</font></font><em><font><font>迭代式</font></font></em><font><font>或</font></font><em><font><font>迭代变量</font></font></em><font><font>。</font></font>
                        </li>
                        <li><font><font>我们将调用</font></font><code>prod</code><font><font>的</font></font><em><font><font>迭代变量</font></font></em><font><font>或者干脆</font></font><em><font><font>ITER变量</font></font></em><font><font>。</font></font>
                        </li>
                    </ul>
                    <p><font><font>请注意，</font></font><code>prod</code><font><font>iter变量的作用域为</font></font><code>&lt;tr&gt;</code><font><font>元素，这意味着它可用于内部标记，如</font></font><code>&lt;td&gt;</code><font><font>。</font></font>
                    </p>
                </section>
                <section class="level3" id="iterable-values">
                    <h3><font><font>可迭代的值</font></font></h3>
                    <p>
                        <font><font>该</font></font><code>java.util.List</code><font><font>班是不是可以用于Thymeleaf迭代onlyvalue。</font><font>有一个很完整的一套被认为是对象的</font></font><em><font><font>迭代</font></font></em><font><font>通过</font></font><code>th:each</code><font><font>属性：</font></font>
                    </p>
                    <ul>
                        <li><font><font>任何对象实现 </font></font><code>java.util.Iterable</code></li>
                        <li>
                            <font><font>任何对象实现</font></font><code>java.util.Enumeration</code><font><font>。</font></font>
                        </li>
                        <li><font><font>任何实现的对象</font></font><code>java.util.Iterator</code><font><font>，其值将被迭代器返回，而不需要在内存中缓存所有值。</font></font>
                        </li>
                        <li><font><font>任何对象实现</font></font><code>java.util.Map</code><font><font>。</font><font>迭代映射时，迭代变量将是类</font></font><code>java.util.Map.Entry</code><font><font>。</font></font>
                        </li>
                        <li><font><font>任何数组。</font></font></li>
                        <li><font><font>任何其他对象将被视为包含对象本身的单值列表。</font></font></li>
                    </ul>
                </section>
            </section>
            <section class="level2" id="keeping-iteration-status">
                <h2><font><font>6.2保持迭代状态</font></font></h2>
                <p>
                    <font><font>使用</font></font><code>th:each</code><font><font>时，Thymeleaf提供了一种有助于跟踪您的迭代状态的机制：</font></font><em><font><font>状态变量</font></font></em><font><font>。</font></font>
                </p>
                <p><font><font>状态变量在属性中定义</font></font><code>th:each</code><font><font>并包含以下数据：</font></font></p>
                <ul>
                    <li><font><font>当前的</font></font><em><font><font>迭代索引</font></font></em><font><font>，从0开始。这是</font></font><code>index</code><font><font>属性。</font></font>
                    </li>
                    <li><font><font>当前的</font></font><em><font><font>迭代索引</font></font></em><font><font>，从1开始。这是</font></font><code>count</code><font><font>属性。</font></font>
                    </li>
                    <li>
                        <font><font>迭代变量中元素的总量。</font><font>这是</font></font><code>size</code><font><font>酒店。</font></font>
                    </li>
                    <li>
                        <font><font>的</font></font><em><font><font>ITER变量</font></font></em><font><font>对于每次迭代。</font><font>这是</font></font><code>current</code><font><font>酒店。</font></font>
                    </li>
                    <li>
                        <font><font>当前的迭代是偶数还是奇数。</font><font>这些是</font></font><code>even/odd</code><font><font>布尔属性。</font></font>
                    </li>
                    <li>
                        <font><font>当前的迭代是否是第一个迭代。</font><font>这是</font></font><code>first</code><font><font>布尔属性。</font></font>
                    </li>
                    <li>
                        <font><font>当前的迭代是否是最后一个迭代。</font><font>这是</font></font><code>last</code><font><font>布尔属性。</font></font>
                    </li>
                </ul>
                <p><font><font>我们来看看我们如何用前面的例子来使用它：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>prod,iterStat : ${prods}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${iterStat.odd}? <span
          class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.name}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Onions<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.price}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2.41<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.inStock}? #{true} : #{false}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>yes<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>状态变量（</font></font><code>iterStat</code><font><font>在本示例中）是</font></font><code>th:each</code><font><font>通过在iter变量本身之后写入其名称（以逗号分隔</font><font>）来定义的</font><font>。</font><font>就像iter变量一样，状态变量也被定义为由保存该</font></font><code>th:each</code><font><font>属性</font><font>的标签定义的代码</font><font>段。</font></font>
                </p>
                <p><font><font>我们来看看处理我们的模板的结果：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span
        class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
            class="token punctuation">&gt;</span></span>Good Thymes Virtual Grocery<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span
            class="token attr-name">content</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>text/html; charset<span
            class="token punctuation">=</span>UTF-8<span class="token punctuation">"</span></span> <span
            class="token attr-name">http-equiv</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>Content-Type<span
            class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
            class="token attr-name">rel</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>stylesheet<span
            class="token punctuation">"</span></span> <span class="token attr-name">type</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
            class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all<span
            class="token punctuation">"</span></span> <span class="token attr-name">href</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>/gtvg/css/gtvg.css<span
            class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span
            class="token punctuation">&gt;</span></span>Product list<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span
                            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
              class="token attr-name">class</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>Fresh Sweet Basil<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>4.99<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>Italian Tomato<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>1.25<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>no<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
              class="token attr-name">class</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>Yellow Bell Pepper<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>2.50<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>Old Cheddar<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>18.75<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>/gtvg/<span class="token punctuation">"</span></span> <span
              class="token attr-name">shape</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>rect<span
              class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>Return to home<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>请注意，我们的迭代状态变量已经完美运行，仅将</font></font><code>odd</code><font><font>CSS类建立到奇数行。</font></font>
                </p>
                <p><font><font>如果没有显式设置状态变量，Thymeleaf将始终为</font></font><code>Stat</code><font><font>迭代变量的名称</font><font>后缀创建一个</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>prod : ${prods}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${prodStat.odd}? <span
          class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.name}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Onions<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.price}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2.41<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.inStock}? #{true} : #{false}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>yes<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="optimizing-through-lazy-retrieval-of-data">
                <h2><font><font>6.3通过懒惰检索数据进行优化</font></font></h2>
                <p><font><font>有时，我们可能希望优化数据集合的检索（例如从数据库），以便只有在真正使用这些集合时才会检索这些集合。</font></font></p>
                <blockquote>
                    <p><font><font>实际上，这是可以应用于</font></font><em><font><font>任何</font></font></em><font><font>数据的东西，但是考虑到内存中集合的大小，检索要迭代的集合是这种情况的最常见的情况。</font></font>
                    </p>
                </blockquote>
                <p><font><font>为了支持这一点，Thymeleaf提供了一种</font></font><em><font><font>延迟加载上下文变量的机制</font></font></em><font><font>。</font><font>实现接口的</font></font><code>ILazyContextVariable</code><font><font>上下文变量（最可能通过扩展其</font></font><code>LazyContextVariable</code><font><font>默认实现）将在执行时解决。</font><font>例如：</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java">context<span
                        class="token punctuation">.</span><span class="token function">setVariable</span><span
                        class="token punctuation">(</span>
     <span class="token string">"users"</span><span class="token punctuation">,</span>
     <span class="token keyword">new</span> <span class="token class-name">LazyContextVariable</span><span
                            class="token operator">&lt;</span>List<span class="token operator">&lt;</span>User<span
                            class="token operator">&gt;&gt;</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span> <span class="token punctuation">{</span><font></font>
         @Override<font></font>
         <span class="token keyword">protected</span> List<span class="token operator">&lt;</span>User<span
                            class="token operator">&gt;</span> <span class="token function">loadValue</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span> <span
                            class="token punctuation">{</span>
             <span class="token keyword">return</span> databaseRepository<span class="token punctuation">.</span><span
                            class="token function">findAllUsers</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
         <span class="token punctuation">}</span>
     <span class="token punctuation">}</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span></code></pre>
                <p>
                    <font><font>这个变量可以在不知道其</font></font><em><font><font>懒惰的</font></font></em><font><font>情况下使用</font><font>，代码如下：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>ul</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>u : ${users}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>text</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${u.name}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>user name<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>li</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>但在同一时间，将永远不会被初始化（其</font></font><code>loadValue()</code><font><font>方法永远不会被调用），如果</font></font><code>condition</code><font><font>计算结果为</font></font><code>false</code><font><font>在这样的代码：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>ul</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>if</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${condition}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>u : ${users}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>text</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${u.name}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>user name<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>li</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
        </section>
        <section class="level1" id="conditional-evaluation">
            <h1><font><font>7条件评估</font></font></h1>
            <section class="level2" id="simple-conditionals-if-and-unless">
                <h2><font><font>7.1简单条件：“如果”和“除非”</font></font></h2>
                <p><font><font>有时，如果满足某个条件，您将需要一个模板片段才能显示在结果中。</font></font></p>
                <p><font><font>例如，假设我们想在我们的产品表中显示一列列，其中包含每个产品存在的注释数，如果有任何评论，则指向该产品的注释详细信息页面的链接。</font></font></p>
                <p><font><font>为了做到这一点，我们将使用这个</font></font><code>th:if</code><font><font>属性：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>COMMENTS<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>prod : ${prods}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${prodStat.odd}? <span
          class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.name}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Onions<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.price}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2.41<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.inStock}? #{true} : #{false}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>yes<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
              class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span
              class="token punctuation">"</span>${#lists.size(prod.comments)}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>comments.html<span class="token punctuation">"</span></span>
         <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>@{/product/comments(prodId<span class="token punctuation">=</span>${prod.id})}<span
                  class="token punctuation">"</span></span>
         <span class="token attr-name"><span class="token namespace">th:</span>if</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>${not #lists.isEmpty(prod.comments)}<span class="token punctuation">"</span></span><span
                  class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>在这里可以看到很多东西，所以让我们来关注重点：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                        class="token attr-name">href</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>comments.html<span
                        class="token punctuation">"</span></span>
   <span class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>@{/product/comments(prodId<span
                            class="token punctuation">=</span>${prod.id})}<span
                            class="token punctuation">"</span></span>
   <span class="token attr-name"><span class="token namespace">th:</span>if</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${not #lists.isEmpty(prod.comments)}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>这将创建一个链接到评论页面（带有URL </font></font><code>/product/comments</code><font><font>），其</font></font><code>prodId</code><font><font>参数设置为</font></font><code>id</code><font><font>产品，但仅当产品有任何评论时。</font></font>
                </p>
                <p><font><font>我们来看看结果的标记：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>COMMENTS<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Fresh Sweet Basil<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>4.99<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Italian Tomato<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>1.25<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>no<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>/gtvg/product/comments?prodId<span
              class="token punctuation">=</span>2<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Yellow Bell Pepper<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>2.50<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Old Cheddar<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>18.75<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>/gtvg/product/comments?prodId<span
              class="token punctuation">=</span>4<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>完善！</font><font>这正是我们想要的。</font></font></p>
                <p>
                    <font><font>请注意，</font></font><code>th:if</code><font><font>属性不仅将评估</font></font><em><font><font>布尔</font></font></em><font><font>条件。</font><font>它的功能有点超出了它，它将</font></font><code>true</code><font><font>按照以下规则</font><font>评估指定的表达式</font><font>：</font></font>
                </p>
                <ul>
                    <li><font><font>如果值不为空：
                    </font></font>
                        <ul>
                            <li><font><font>如果值为布尔值，则为</font></font><code>true</code><font><font>。</font></font></li>
                            <li><font><font>如果值是数字，并且不为零</font></font></li>
                            <li><font><font>如果值是一个字符且不为零</font></font></li>
                            <li><font><font>如果value是String，而不是“false”，“off”或“no”</font></font></li>
                            <li><font><font>如果值不是布尔值，数字，字符或字符串。</font></font></li>
                        </ul>
                    </li>
                    <li><font><font>（如果值为null，则th：如果将为false）。</font></font></li>
                </ul>
                <p>
                    <font><font>此外，</font></font><code>th:if</code><font><font>还有一个逆属性，</font></font><code>th:unless</code><font><font>我们可以在前面的例子中使用，而不是</font></font><code>not</code><font><font>在OGNL表达式</font><font>中使用</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                        class="token attr-name">href</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>comments.html<span
                        class="token punctuation">"</span></span>
   <span class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>@{/comments(prodId<span
                            class="token punctuation">=</span>${prod.id})}<span
                            class="token punctuation">"</span></span>
   <span class="token attr-name"><span class="token namespace">th:</span>unless</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>${#lists.isEmpty(prod.comments)}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="switch-statements">
                <h2><font><font>7.2切换语句</font></font></h2>
                <p>
                    <font><font>还有一种方法可以有条件地使用</font><font>Java </font><font>中的</font></font><em><font><font>开关</font></font></em><font><font>结构等价物：</font></font><code>th:switch</code><font><font>/ </font></font><code>th:case</code><font><font>attribute
                    set </font><font>来显示内容</font><font>。</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>switch</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${user.role}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
          class="token attr-name"><span class="token namespace">th:</span>case</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span><span
          class="token punctuation">'</span>admin<span class="token punctuation">'</span><span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>User is an administrator<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
          class="token attr-name"><span class="token namespace">th:</span>case</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>#{roles.manager}<span
          class="token punctuation">"</span></span><span
          class="token punctuation">&gt;</span></span>User is a manager<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>请注意，只要一个</font></font><code>th:case</code><font><font>属性被评估为</font></font><code>true</code><font><font>，</font></font><code>th:case</code><font><font>则相同切换上下文中的</font><font>每个其他</font><font>属性都将被评估为</font></font><code>false</code><font><font>。</font></font>
                </p>
                <p><font><font>默认选项指定为</font></font><code>th:case="*"</code><font><font>：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>switch</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${user.role}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
          class="token attr-name"><span class="token namespace">th:</span>case</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span><span
          class="token punctuation">'</span>admin<span class="token punctuation">'</span><span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>User is an administrator<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
          class="token attr-name"><span class="token namespace">th:</span>case</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>#{roles.manager}<span
          class="token punctuation">"</span></span><span
          class="token punctuation">&gt;</span></span>User is a manager<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
          class="token attr-name"><span class="token namespace">th:</span>case</span><span
          class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>*<span class="token punctuation">"</span></span><span
          class="token punctuation">&gt;</span></span>User is some other thing<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
        </section>
        <section class="level1" id="template-layout">
            <h1><font><font>8模板布局</font></font></h1>
            <section class="level2" id="including-template-fragments">
                <h2><font><font>8.1包括模板片段</font></font></h2>
                <section class="level3" id="defining-and-referencing-fragments">
                    <h3><font><font>定义和引用片段</font></font></h3>
                    <p><font><font>在我们的模板中，我们经常希望从其他模板中添加零件，如页脚，页眉，菜单等部分</font></font></p>
                    <p>
                        <font><font>为了做到这一点，Thymeleaf需要我们定义这些部分，“片段”，以便包含，可以使用</font></font><code>th:fragment</code><font><font>属性</font><font>来完成</font><font>。</font></font>
                    </p>
                    <p>
                        <font><font>假设我们要向所有杂货页面添加标准版权页脚，因此我们创建一个</font></font><code>/WEB-INF/templates/footer.html</code><font><font>包含此代码</font><font>的</font><font>文件：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span
        class="token attr-name"><span class="token namespace">xmlns:</span>th</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span><a href="http://www.thymeleaf.org"
                                                                                     rel="noreferrer"
                                                                                     style="cursor:help;display:inline !important;"
                                                                                     target="_blank">http://www.thymeleaf.org</a><span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
            class="token attr-name"><span class="token namespace">th:</span>fragment</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>copy<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token entity" title="©">&amp;copy;</span> 2011 The Good Thymes Virtual Grocery
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p>
                        <font><font>上面的代码定义了一个片段</font></font><code>copy</code><font><font>，我们可以使用其中一个</font></font><code>th:insert</code><font><font>或</font></font><code>th:replace</code><font><font>多个属性</font><font>轻松地包含在我们的主页中</font><font>（并且</font></font><code>th:include</code><font><font>，尽管Thymeleaf
                        3.0不再推荐使用它）：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>body</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  ...<font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
          class="token attr-name"><span class="token namespace">th:</span>insert</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>~{footer :: copy}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                                class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p>
                        <font><font>请注意，</font></font><code>th:insert</code><font><font>期望一个</font></font><em><font><font>片段表达式</font></font></em><font><font>（</font></font><code>~{...}</code><font><font>），它是</font></font><em><font><font>一个导致片段的表达式</font></font></em><font><font>。</font><font>虽然在上面的例子中，这是一种不复杂的</font></font><em><font><font>片段表达</font></font></em><font><font>时，（
                        ，</font></font><code>~{</code><font><font>）</font></font><code>}</code><font><font>包围完全是可选的，所以上面的代码将相当于：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>body</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  ...<font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
          class="token attr-name"><span class="token namespace">th:</span>insert</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>footer :: copy<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                                class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                </section>
                <section class="level3" id="fragment-specification-syntax">
                    <h3><font><font>片段规范语法</font></font></h3>
                    <p>
                        <font></font><em><font><font>片段表达式</font></font></em><font><font>的语法</font><font>是非常简单的。</font><font>有三种不同的格式：</font></font>
                    </p>
                    <ul>
                        <li>
                            <code>"~{templatename::selector}"</code><font><font>包含在命名的模板上应用指定的标记选择器导致的片段</font></font><code>templatename</code><font><font>。</font><font>请注意，</font></font><code>selector</code><font><font>可以只是一个片段名称，所以你可以指定</font></font><code>~{templatename::fragmentname}</code><font><font>像</font></font><code>~{footer
                            :: copy}</code><font><font>上面</font><font>那样简单的</font><font>东西</font><font>。</font></font>
                        </li>
                    </ul>
                    <blockquote>
                        <p>
                            <font><font>标记选择器语法由底层的AttoParser解析库定义，类似于XPath表达式或CSS选择器。</font><font>有关</font><font>详细信息，</font><font>请参阅</font></font><a
                                href="#appendix-c-markup-selector-syntax"><font><font>附录C.</font></font></a><font></font>
                        </p>
                    </blockquote>
                    <ul>
                        <li>
                            <code>"~{templatename}"</code><font><font>包括完整的模板命名</font></font><code>templatename</code><font><font>。</font></font>
                        </li>
                    </ul>
                    <blockquote>
                        <p><font><font>请注意，您在</font></font><code>th:insert</code><font><font>/ </font></font><code>th:replace</code><font><font>tags中</font><font>使用的模板名称</font><font>必须由Template
                            Engine当前使用的Template Resolver解析。</font></font></p>
                    </blockquote>
                    <ul>
                        <li><code>~{::selector}"</code><font><font>或</font></font><code>"~{this::selector}"</code><font><font>包含同一模板的片段。</font></font>
                        </li>
                    </ul>
                    <p>
                        <font><font>双方</font></font><code>templatename</code><font><font>并</font></font><code>selector</code><font><font>在上面的例子可以是全功能的表达式（甚至条件语句！），如：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>insert</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>footer :: (${user.isAdmin}? #{footer.admin} : #{footer.normaluser})<span
                            class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span></code></pre>
                    <p>
                        <font><font>请再次注意周围的</font></font><code>~{...}</code><font><font>信封在</font></font><code>th:insert</code><font><font>/中</font><font>是否可选</font></font><code>th:replace</code><font><font>。</font></font>
                    </p>
                    <p>
                        <font><font>片段可以包括任何</font></font><code>th:*</code><font><font>属性。</font><font>一旦片段被包含在目标模板（具有</font></font><code>th:insert</code><font><font>/ </font></font><code>th:replace</code><font><font>attribute）的</font><font>模板中，这些属性将被评估</font><font>，并且它们将能够引用此目标模板中定义的任何上下文变量。</font></font>
                    </p>
                    <blockquote>
                        <p>
                            <font><font>这种分片方法的一大优点是，您可以将页面中的片段写入浏览器完美显示的页面，并具有完整而</font></font><em><font><font>有效的</font></font></em><font><font>标记结构，同时仍保留使Thymeleaf包含在其他模板中的功能。</font></font>
                        </p>
                    </blockquote>
                </section>
                <section class="level3" id="referencing-fragments-without-thfragment">
                    <h3><font><font>没有引用片段 </font></font><code>th:fragment</code></h3>
                    <p><font><font>由于Markup Selectors的功能，我们可以包括不使用任何</font></font><code>th:fragment</code><font><font>属性的片段。</font><font>甚至可以使用不同于Thymeleaf知识的不同应用程序的标记代码：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
        class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span
        class="token punctuation">"</span>copy-section<span class="token punctuation">"</span></span><span
        class="token punctuation">&gt;</span></span>
  <span class="token entity" title="©">&amp;copy;</span> 2011 The Good Thymes Virtual Grocery
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                    <p>
                        <font><font>我们可以使用上面的片段简单地引用它的</font></font><code>id</code><font><font>属性，类似于CSS选择器：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>body</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  ...<font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
          class="token attr-name"><span class="token namespace">th:</span>insert</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>~{footer :: #copy-section}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                                class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                </section>
                <section class="level3" id="difference-between-thinsert-and-threplace-and-thinclude">
                    <h3>
                        <font></font><code>th:insert</code><font><font>和</font></font><code>th:replace</code><font><font>（和</font></font><code>th:include</code><font><font>）</font><font>之间的差异</font></font>
                    </h3>
                    <p><font></font><code>th:insert</code><font><font>和</font></font><code>th:replace</code><font><font>（和</font></font><code>th:include</code><font><font>，不推荐3.0 </font><font>之间有什么</font><font>区别）？</font></font>
                    </p>
                    <ul>
                        <li><p><code>th:insert</code><font><font> 是最简单的：它将简单地插入指定的片段作为它的主机标签的主体。</font></font></p></li>
                        <li><p>
                            <code>th:replace</code><font><font>实际上</font></font><em><font><font>用</font></font></em><font><font>指定的片段</font><em><font>替换</font></em><font>了它的主机标签。</font></font>
                        </p></li>
                        <li><p><code>th:include</code><font><font>是类似的</font></font><code>th:insert</code><font><font>，而不是插入片段，它只插入</font><font>这个片段</font><font>的</font></font><em><font><font>内容</font></font></em><font><font>。</font></font>
                        </p></li>
                    </ul>
                    <p><font><font>所以这样一个HTML片段：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>footer</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>fragment</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>copy<span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token entity" title="©">&amp;copy;</span> 2011 The Good Thymes Virtual Grocery
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>footer</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p>
                        <font><font>...在主机</font></font><code>&lt;div&gt;</code><font><font>标签</font><font>中包含三次</font><font>，如下所示：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>body</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  ...<font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
          class="token attr-name"><span class="token namespace">th:</span>insert</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>footer :: copy<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
          class="token attr-name"><span class="token namespace">th:</span>replace</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>footer :: copy<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
          class="token attr-name"><span class="token namespace">th:</span>include</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>footer :: copy<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                                class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>...将导致：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>body</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  ...<font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>footer</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token entity" title="©">&amp;copy;</span> 2011 The Good Thymes Virtual Grocery
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>footer</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>footer</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token entity" title="©">&amp;copy;</span> 2011 The Good Thymes Virtual Grocery
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>footer</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token entity" title="©">&amp;copy;</span> 2011 The Good Thymes Virtual Grocery
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                </section>
            </section>
            <section class="level2" id="parameterizable-fragment-signatures">
                <h2><font><font>8.2可参数化的片段签名</font></font></h2>
                <p><font><font>为了</font><font>为模板片段</font><font>创建一个更多</font></font><em><font><font>类似功能的</font></font></em><font><font>机制，用定义</font></font><code>th:fragment</code><font><font>的片段可以指定一组参数：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>fragment</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>frag (onevar,twovar)<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${onevar} + <span
            class="token punctuation">'</span> - <span class="token punctuation">'</span> + ${twovar}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这需要使用这两种语法中的一种从</font></font><code>th:insert</code><font><font>或</font><font>调用片段</font></font><code>th:replace</code><font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>replace</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>::frag (${value1},${value2})<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                        class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
        class="token attr-name"><span class="token namespace">th:</span>replace</span><span
        class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>::frag (onevar<span
        class="token punctuation">=</span>${value1},twovar<span class="token punctuation">=</span>${value2})<span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>请注意，顺序在最后一个选项中不重要：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>replace</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>::frag (twovar<span class="token punctuation">=</span>${value2},onevar<span
                        class="token punctuation">=</span>${value1})<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <section class="level3" id="fragment-local-variables-without-fragment-arguments">
                    <h3><font><font>不带片段参数的片段局部变量</font></font></h3>
                    <p><font><font>即使片段被定义为没有这样的参数：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>fragment</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>frag<span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>我们可以使用上面指定的第二个语法来调用它们（只有第二个语法）：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>replace</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>::frag (onevar<span class="token punctuation">=</span>${value1},twovar<span
                            class="token punctuation">=</span>${value2})<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span></code></pre>
                    <p>
                        <font><font>这将相当于组合</font></font><code>th:replace</code><font><font>和</font></font><code>th:with</code><font><font>：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>replace</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>::frag<span
                            class="token punctuation">"</span></span> <span class="token attr-name"><span
                            class="token namespace">th:</span>with</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>onevar<span
                            class="token punctuation">=</span>${value1},twovar<span class="token punctuation">=</span>${value2}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span></code></pre>
                    <p><strong><font><font>请注意</font></font></strong><font><font>，片段的局部变量规范 - 无论是否具有参数签名 -
                        都不会导致上下文在执行之前被清空。</font><font>片段仍然能够访问调用模板中正在使用的每个上下文变量，就像它们当前一样。</font></font></p>
                </section>
                <section class="level3" id="thassert-for-in-template-assertions">
                    <h3><font><font>th：assert for in-template assertions</font></font></h3>
                    <p><font><font>该</font></font><code>th:assert</code><font><font>属性可以指定一个逗号分隔的表达式列表，该列表应该被评估，并为每个评估产生真实的，如果没有，则引发异常。</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>assert</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>${onevar},(${twovar} !<span
                            class="token punctuation">=</span> 43)<span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span>...<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>这有助于验证片段签名中的参数：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>header</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>fragment</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>contentheader(title)<span
                            class="token punctuation">"</span></span> <span class="token attr-name"><span
                            class="token namespace">th:</span>assert</span><span class="token attr-value"><span
                            class="token punctuation">=</span><span class="token punctuation">"</span>${!#strings.isEmpty(title)}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                            class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>header</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                </section>
            </section>
            <section class="level2" id="flexible-layouts-beyond-mere-fragment-insertion">
                <h2><font><font>8.3灵活的布局：不仅仅是片段插入</font></font></h2>
                <p>
                    <font><font>感谢</font></font><em><font><font>片段表达式</font></font></em><font><font>，我们可以为不是文本，数字，bean对象的</font><em><font>片段</font></em><font>指定参数，而是为标记</font><em><font>片段</font></em><font>指定参数。</font></font>
                </p>
                <p><font><font>这允许我们以一种方式创建我们的片段，使得它们可以</font></font><em><font><font>丰富</font></font></em><font><font>来自调用</font></font><strong><font><font>模板的</font></font></strong><font><font>标记，从而产生非常灵活的</font><strong><font>模板布局机制</font></strong><font>。</font></font>
                </p>
                <p>
                    <font><font>注意</font><font>下面片段中</font><font>使用</font></font><code>title</code><font><font>和</font></font><code>links</code><font><font>变量：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>head</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>fragment</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>common_header(title,links)<span
                        class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span> <span
          class="token attr-name"><span class="token namespace">th:</span>replace</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${title}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>The awesome application<span
                            class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token comment" spellcheck="true">&lt;!-- Common styles and scripts --&gt;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name">type</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
          class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
          class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>all<span class="token punctuation">"</span></span> <span
          class="token attr-name"><span class="token namespace">th:</span>href</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@{/css/awesomeapp.css}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>shortcut icon<span class="token punctuation">"</span></span> <span
          class="token attr-name"><span class="token namespace">th:</span>href</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@{/images/favicon.ico}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
          class="token attr-name">type</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>text/javascript<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>src</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>@{/sh/scripts/codebase.js}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                            class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token comment" spellcheck="true">&lt;!--/* Per-page placeholder for additional links */--&gt;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span
          class="token namespace">th:</span>block</span> <span class="token attr-name"><span
          class="token namespace">th:</span>replace</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${links}<span
          class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>我们现在可以将这个片段称为：</font></font></p>
                <pre class="  language-html"><code class="  language-html">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span> <span
        class="token attr-name"><span class="token namespace">th:</span>replace</span><span
        class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base :: common_header(~{::title},~{::link})<span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
          class="token punctuation">&gt;</span></span>Awesome - Main<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name"><span class="token namespace">th:</span>href</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@{/css/bootstrap.min.css}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name"><span class="token namespace">th:</span>href</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@{/themes/smoothness/jquery-ui.css}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                <p><font><font>......，结果会用实际</font></font><code>&lt;title&gt;</code><font><font>和</font></font><code>&lt;link&gt;</code><font><font>我们调用模板标签的值</font></font><code>title</code><font><font>和</font></font><code>links</code><font><font>变量，导致我们的片段插入时被定制：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
        class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
          class="token punctuation">&gt;</span></span>Awesome - Main<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token comment" spellcheck="true">&lt;!-- Common styles and scripts --&gt;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name">type</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
          class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
          class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>all<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/css/awesomeapp.css<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>shortcut icon<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/images/favicon.ico<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
          class="token attr-name">type</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>text/javascript<span
          class="token punctuation">"</span></span> <span class="token attr-name">src</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>/awe/sh/scripts/codebase.js<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                            class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/css/bootstrap.min.css<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/themes/smoothness/jquery-ui.css<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                <section class="level3" id="using-the-empty-fragment">
                    <h3><font><font>使用空的片段</font></font></h3>
                    <p>
                        <font><font>一个特殊的片段表达式，</font></font><em><font><font>空的fragment</font></font></em><font><font>（</font></font><code>~{}</code><font><font>）可以用来指定</font></font><em><font><font>没有标记</font></font></em><font><font>。</font><font>使用前面的例子：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>head</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>replace</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>base :: common_header(~{::title},~{})<span
                            class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
          class="token punctuation">&gt;</span></span>Awesome - Main<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                    <p>
                        <font><font>请注意，fragment（</font></font><code>links</code><font><font>）</font><font>的第二个参数如何</font><font>设置为</font></font><em><font><font>空的片段</font></font></em><font><font>，因此没有为</font></font><code>&lt;th:block
                        th:replace="${links}" /&gt;</code><font><font>块</font><font>写入</font><font>：</font></font></p>
                    <pre class="  language-html"><code class="  language-html">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
        class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
          class="token punctuation">&gt;</span></span>Awesome - Main<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token comment" spellcheck="true">&lt;!-- Common styles and scripts --&gt;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name">type</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
          class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
          class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>all<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/css/awesomeapp.css<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>shortcut icon<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/images/favicon.ico<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
          class="token attr-name">type</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>text/javascript<span
          class="token punctuation">"</span></span> <span class="token attr-name">src</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>/awe/sh/scripts/codebase.js<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                </section>
                <section class="level3" id="using-the-no-operation-token">
                    <h3><font><font>使用无操作令牌</font></font></h3>
                    <p><font><font>如果我们只想让我们的片段将其当前标记用作默认值，那么no-op也可以用作片段的参数。</font><font>再次，使用</font></font><code>common_header</code><font><font>示例：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span> <span
        class="token attr-name"><span class="token namespace">th:</span>replace</span><span
        class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base :: common_header(_,~{::link})<span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
          class="token punctuation">&gt;</span></span>Awesome - Main<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name"><span class="token namespace">th:</span>href</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@{/css/bootstrap.min.css}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name"><span class="token namespace">th:</span>href</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@{/themes/smoothness/jquery-ui.css}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                    <p>
                        <font><font>看看</font></font><code>title</code><font><font>参数（</font></font><code>common_header</code><font><font>片段的</font><font>第一个参数</font><font>）如何设置为</font></font><em><font><font>no-op</font></font></em><font><font>（</font></font><code>_</code><font><font>），这导致片段的这部分不被执行（</font></font><code>title</code><font><font>= </font></font><em><font><font>no-operation</font></font></em><font><font>）：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html">  <span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>title</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>replace</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>${title}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>The awesome application<span
                            class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>所以结果是：</font></font></p>
                    <pre class="  language-html"><code class="  language-html">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
        class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
          class="token punctuation">&gt;</span></span>The awesome application<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token comment" spellcheck="true">&lt;!-- Common styles and scripts --&gt;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name">type</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
          class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
          class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>all<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/css/awesomeapp.css<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>shortcut icon<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/images/favicon.ico<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
          class="token attr-name">type</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>text/javascript<span
          class="token punctuation">"</span></span> <span class="token attr-name">src</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>/awe/sh/scripts/codebase.js<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
                                class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/css/bootstrap.min.css<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
          class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span
          class="token attr-name">href</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>/awe/themes/smoothness/jquery-ui.css<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                </section>
                <section class="level3" id="advanced-conditional-insertion-of-fragments">
                    <h3><font><font>高级条件插入片段</font></font></h3>
                    <p>
                        <font><font>双方的可用性</font></font><em><font><font>emtpy片段</font></font></em><font><font>和</font></font><em><font><font>无操作令牌</font></font></em><font><font>可以让我们在一个非常简单而优雅的方式进行片段的插入条件。</font></font>
                    </p>
                    <p>
                        <font><font>例如，我们可以这样做，以便</font><em><font>仅</font></em><font>当用户是管理员时</font><font>插入我们的</font></font><code>common
                        ::
                        adminhead</code><font><font>片段</font><font>，并且不插入（emtpy片段）（如果不是）：</font></font><em><font></font></em><font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
        class="token attr-name"><span class="token namespace">th:</span>insert</span><span
        class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${user.isAdmin()} ? ~{common :: adminhead} : ~{}<span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                                class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
                                class="token punctuation">&gt;</span></span>
...</code></pre>
                    <p>
                        <font><font>另外，</font><font>只有满足指定的条件</font><font>，我们才可以使用</font></font><em><font><font>无操作令牌</font></font></em><font><font>来插入片段，但是如果不满足条件，则不需要修改则保留标记：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
        class="token attr-name"><span class="token namespace">th:</span>insert</span><span
        class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${user.isAdmin()} ? ~{common :: adminhead} : _<span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    Welcome [[${user.name}]], click <span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;</span>a</span> <span class="token attr-name"><span
                                class="token namespace">th:</span>href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span
                                class="token punctuation">"</span>@{/support}<span
                                class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>here<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>a</span><span
                                class="token punctuation">&gt;</span></span> for help-desk support.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                    <p><font><font>另外，如果我们配置了我们的模板解析器来</font></font><em><font><font>检查</font></font></em><font><font>模板资源的存在（通过它们的</font></font><code>checkExistence</code><font><font>标志），我们可以使用片段本身的存在作为</font></font><em><font><font>默认操作中的</font></font></em><font><font>条件：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html">...
<span class="token comment" spellcheck="true">&lt;!-- The body of the &lt;div&gt; will be used if the "common :: salutation" fragment  --&gt;</span>
<span class="token comment" spellcheck="true">&lt;!-- does not exist (or is empty).                                              --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
        class="token attr-name"><span class="token namespace">th:</span>insert</span><span
        class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>~{common :: salutation} ?: _<span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    Welcome [[${user.name}]], click <span class="token tag"><span class="token tag"><span
                                class="token punctuation">&lt;</span>a</span> <span class="token attr-name"><span
                                class="token namespace">th:</span>href</span><span class="token attr-value"><span
                                class="token punctuation">=</span><span
                                class="token punctuation">"</span>@{/support}<span
                                class="token punctuation">"</span></span><span
                                class="token punctuation">&gt;</span></span>here<span class="token tag"><span
                                class="token tag"><span class="token punctuation">&lt;/</span>a</span><span
                                class="token punctuation">&gt;</span></span> for help-desk support.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span>
...</code></pre>
                </section>
            </section>
            <section class="level2" id="removing-template-fragments">
                <h2><font><font>8.4删除模板片段</font></font></h2>
                <p><font><font>回到示例应用程序，让我们回顾一下我们的产品列表模板的最后一个版本：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>COMMENTS<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>prod : ${prods}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${prodStat.odd}? <span
          class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.name}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Onions<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.price}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2.41<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.inStock}? #{true} : #{false}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>yes<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
              class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span
              class="token punctuation">"</span>${#lists.size(prod.comments)}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>comments.html<span class="token punctuation">"</span></span>
         <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>@{/product/comments(prodId<span class="token punctuation">=</span>${prod.id})}<span
                  class="token punctuation">"</span></span>
         <span class="token attr-name"><span class="token namespace">th:</span>unless</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>${#lists.isEmpty(prod.comments)}<span
                  class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这个代码只是一个模板，但是作为一个静态页面（当没有Thymeleaf处理它的浏览器直接打开它）它不会做一个漂亮的原型。</font></font></p>
                <p>
                    <font><font>为什么？</font><font>因为尽管浏览器完全可以显示，该表只有一行，而这行有模拟数据。</font><font>作为一个原型，它根本看起来不够现实，我们应该有多个产品，</font></font><em><font><font>我们需要更多的行</font></font></em><font><font>。</font></font>
                </p>
                <p><font><font>所以我们来补充一下：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>COMMENTS<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>prod : ${prods}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${prodStat.odd}? <span
          class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.name}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Onions<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.price}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2.41<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.inStock}? #{true} : #{false}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>yes<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
              class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span
              class="token punctuation">"</span>${#lists.size(prod.comments)}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>comments.html<span class="token punctuation">"</span></span>
         <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>@{/product/comments(prodId<span class="token punctuation">=</span>${prod.id})}<span
                  class="token punctuation">"</span></span>
         <span class="token attr-name"><span class="token namespace">th:</span>unless</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>${#lists.isEmpty(prod.comments)}<span
                  class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Blue Lettuce<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>9.55<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>no<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Mild Cinnamon<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>1.99<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>comments.html<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>好的，现在我们有三个，肯定更好的一个原型。</font><font>但是，当我们用Thymeleaf处理它会发生什么？</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>COMMENTS<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Fresh Sweet Basil<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>4.99<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Italian Tomato<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>1.25<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>no<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>/gtvg/product/comments?prodId<span
              class="token punctuation">=</span>2<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Yellow Bell Pepper<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>2.50<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Old Cheddar<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>18.75<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>/gtvg/product/comments?prodId<span
              class="token punctuation">=</span>4<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Blue Lettuce<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>9.55<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>no<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Mild Cinnamon<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>1.99<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>comments.html<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>最后两行是模拟行！</font><font>那么当然它们是：迭代只适用于第一行，所以没有什么理由为什么Thymeleaf应该删除另外两个。</font></font></p>
                <p><font><font>我们需要一种在模板处理过程中删除这两行的方法。</font><font>让我们使用</font></font><code>th:remove</code><font><font>第二个和第三个</font></font><code>&lt;tr&gt;</code><font><font>标签</font><font>上</font><font>的</font><font>属性</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>COMMENTS<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>prod : ${prods}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${prodStat.odd}? <span
          class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.name}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Onions<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.price}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2.41<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${prod.inStock}? #{true} : #{false}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>yes<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
              class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span
              class="token punctuation">"</span>${#lists.size(prod.comments)}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>comments.html<span class="token punctuation">"</span></span>
         <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>@{/product/comments(prodId<span class="token punctuation">=</span>${prod.id})}<span
                  class="token punctuation">"</span></span>
         <span class="token attr-name"><span class="token namespace">th:</span>unless</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>${#lists.isEmpty(prod.comments)}<span
                  class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>remove</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>all<span class="token punctuation">"</span></span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Blue Lettuce<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>9.55<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>no<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name"><span class="token namespace">th:</span>remove</span><span
          class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>all<span class="token punctuation">"</span></span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Mild Cinnamon<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>1.99<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>comments.html<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>一旦处理，一切都会再次看起来应该是：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
            class="token punctuation">&gt;</span></span>COMMENTS<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Fresh Sweet Basil<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>4.99<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Italian Tomato<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>1.25<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>no<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>/gtvg/product/comments?prodId<span
              class="token punctuation">=</span>2<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Yellow Bell Pepper<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>2.50<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
          class="token attr-name">class</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>Old Cheddar<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>18.75<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
              class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>/gtvg/product/comments?prodId<span
              class="token punctuation">=</span>4<span class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>view<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>这是一个什么</font></font><code>all</code><font><font>的属性值，是什么意思？</font></font><code>th:remove</code><font><font>可以以五种不同的方式行事，具体取决于它的价值：</font></font>
                </p>
                <ul>
                    <li><code>all</code><font><font>：删除包含标签及其所有子项。</font></font></li>
                    <li><code>body</code><font><font>：不要删除包含的标签，但删除其所有的孩子。</font></font></li>
                    <li><code>tag</code><font><font>：删除包含的标签，但不要删除它的孩子。</font></font></li>
                    <li><code>all-but-first</code><font><font>：除去第一个包含标签的所有子项。</font></font></li>
                    <li><code>none</code><font><font>： 没做什么。</font><font>该值对于动态评估是有用的。</font></font></li>
                </ul>
                <p>
                    <font><font>这个</font></font><code>all-but-first</code><font><font>价值有</font><font>什么</font><font>用？</font></font><code>th:remove="all"</code><font><font>原型设计时，</font><font>我们可以节省一些</font><font>时间：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>thead</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
              class="token punctuation">&gt;</span></span>NAME<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
              class="token punctuation">&gt;</span></span>PRICE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
              class="token punctuation">&gt;</span></span>IN STOCK<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
              class="token punctuation">&gt;</span></span>COMMENTS<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>thead</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tbody</span> <span
          class="token attr-name"><span class="token namespace">th:</span>remove</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all-but-first<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
            class="token attr-name"><span class="token namespace">th:</span>each</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>prod : ${prods}<span
            class="token punctuation">"</span></span> <span class="token attr-name"><span
            class="token namespace">th:</span>class</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>${prodStat.odd}? <span
            class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
              class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>${prod.name}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Onions<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
              class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>${prod.price}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2.41<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
              class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>${prod.inStock}? #{true} : #{false}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>yes<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${#lists.size(prod.comments)}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                class="token attr-name">href</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>comments.html<span
                class="token punctuation">"</span></span>
           <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>@{/product/comments(prodId<span class="token punctuation">=</span>${prod.id})}<span
                    class="token punctuation">"</span></span>
           <span class="token attr-name"><span class="token namespace">th:</span>unless</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>${#lists.isEmpty(prod.comments)}<span
                    class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
            class="token attr-name">class</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>odd<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>Blue Lettuce<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>9.55<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>no<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
                class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>Mild Cinnamon<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>1.99<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>yes<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
                class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> comment/s
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                class="token attr-name">href</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>comments.html<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tbody</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>该</font></font><code>th:remove</code><font><font>属性可采取任何</font></font><em><font><font>Thymeleaf标准表示</font></font></em><font><font>，因为它返回允许字符串值中的一个，只要（</font></font><code>all</code><font><font>，</font></font><code>tag</code><font><font>，</font></font><code>body</code><font><font>，</font></font><code>all-but-first</code><font><font>或</font></font><code>none</code><font><font>）。</font></font>
                </p>
                <p><font><font>这意味着删除可能是有条件的，如：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                        class="token attr-name">href</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>/something<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>remove</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>${condition}? tag : none<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Link text not to be removed<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>还要注意，</font></font><code>th:remove</code><font><font>考虑</font></font><code>null</code><font><font>到同义词</font></font><code>none</code><font><font>，所以以下工作与上述示例相同：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                        class="token attr-name">href</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>/something<span
                        class="token punctuation">"</span></span> <span class="token attr-name"><span
                        class="token namespace">th:</span>remove</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>${condition}? tag<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Link text not to be removed<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>在这种情况下，如果</font></font><code>${condition}</code><font><font>是false，</font></font><code>null</code><font><font>将返回，因此不会执行删除。</font></font>
                </p>
            </section>
        </section>
        <section class="level1" id="local-variables">
            <h1><font><font>9个本地变量</font></font></h1>
            <p><font><font>Thymeleaf调用</font></font><em><font><font>局部变量</font></font></em><font><font>为模板的特定片段定义的变量，并且只能在该片段内进行评估。</font></font>
            </p>
            <p><font><font>我们已经看到的一个例子是</font></font><code>prod</code><font><font>我们的产品列表页面</font><font>中的</font><font>iter变量：</font></font>
            </p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>each</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>prod : ${prods}<span
                    class="token punctuation">"</span></span><span
                    class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            <p>
                <font><font>该</font></font><code>prod</code><font><font>变量仅在</font></font><code>&lt;tr&gt;</code><font><font>标签</font><font>的范围内可用</font><font>。</font><font>特别：</font></font>
            </p>
            <ul>
                <li>
                    <font><font>它将可用于</font></font><code>th:*</code><font><font>在该标签中</font><font>执行</font><font>的任何其他</font><font>属性的优先</font></font><em><font><font>级</font></font></em><font><font>低于</font></font><code>th:each</code><font><font>（这意味着它们将在之后执行</font></font><code>th:each</code><font><font>）。</font></font>
                </li>
                <li><font><font>它可用于</font></font><code>&lt;tr&gt;</code><font><font>标签的</font><font>任何子元素</font><font>，例如任何</font></font><code>&lt;td&gt;</code><font><font>元素。</font></font>
                </li>
            </ul>
            <p>
                <font><font>Thymeleaf为您提供了一种使用</font></font><code>th:with</code><font><font>属性</font><font>声明局部变量而不进行迭代的</font><font>方式，其语法与属性值分配类似：</font></font>
            </p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>with</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>firstPer<span class="token punctuation">=</span>${persons[0]}<span
                    class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>
    The name of the first person is <span class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                        class="token namespace">th:</span>text</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>${firstPer.name}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Julius Caesar<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>.
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            <p>
                <font><font>当</font></font><code>th:with</code><font><font>被处理时，该</font></font><code>firstPer</code><font><font>变量被创建为局部变量并被添加到来自上下文的变量映射，使得它可以与上下文中声明的任何其他变量一起使用，但仅在包含</font></font><code>&lt;div&gt;</code><font><font>标记</font><font>的范围内</font><font>。</font></font>
            </p>
            <p><font><font>您可以使用通常的多重赋值语法同时定义多个变量：</font></font></p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>with</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>firstPer<span class="token punctuation">=</span>${persons[0]},secondPer<span
                    class="token punctuation">=</span>${persons[1]}<span class="token punctuation">"</span></span><span
                    class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span>
    The name of the first person is <span class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;</span>span</span> <span class="token attr-name"><span
                        class="token namespace">th:</span>text</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>${firstPer.name}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Julius Caesar<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>.
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
          class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
          class="token punctuation">&gt;</span></span><font></font>
    But the name of the second person is <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
            class="token attr-name"><span class="token namespace">th:</span>text</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${secondPer.name}<span
            class="token punctuation">"</span></span><span
            class="token punctuation">&gt;</span></span>Marcus Antonius<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>.
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>该</font></font><code>th:with</code><font><font>属性允许重用在同一属性中定义的变量：</font></font></p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>with</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>company<span
                    class="token punctuation">=</span>${user.company + <span class="token punctuation">'</span> Co.<span
                    class="token punctuation">'</span>},account<span class="token punctuation">=</span>${accounts[company]}<span
                    class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                    class="token tag"><span class="token tag"><span
                    class="token punctuation">&lt;/</span>div</span><span
                    class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>让我们在我们的杂货店的主页上使用！</font><font>记住我们为输出格式化日期写的代码？</font></font></p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                    class="token punctuation">&gt;</span></span><font></font>
  Today is: <font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
          class="token attr-name"><span class="token namespace">th:</span>text</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${#calendars.format(today,<span
          class="token punctuation">'</span>dd MMMM yyyy<span class="token punctuation">'</span>)}<span
          class="token punctuation">"</span></span><span
          class="token punctuation">&gt;</span></span>13 february 2011<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>那么，如果我们想要这个</font></font><code>"dd MMMM yyyy"</code><font><font>实际上依赖于地区呢？</font><font>例如，我们可能需要将以下消息添加到我们的</font></font><code>home_en.properties</code><font><font>：</font></font>
            </p>
            <pre><code>date.format=MMMM dd'','' yyyy</code></pre>
            <p><font><font>...等同于我们的</font></font><code>home_es.properties</code><font><font>：</font></font></p>
            <pre><code>date.format=dd ''de'' MMMM'','' yyyy</code></pre>
            <p>
                <font><font>现在，我们来使用</font></font><code>th:with</code><font><font>本地化的日期格式变成一个变量，然后在我们的</font></font><code>th:text</code><font><font>表达式中</font><font>使用它</font><font>：</font></font>
            </p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name"><span
                    class="token namespace">th:</span>with</span><span class="token attr-value"><span
                    class="token punctuation">=</span><span class="token punctuation">"</span>df<span
                    class="token punctuation">=</span>#{date.format}<span class="token punctuation">"</span></span><span
                    class="token punctuation">&gt;</span></span>
  Today is: <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${#calendars.format(today,df)}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>13 February 2011<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            <p>
                <font><font>那干净而简单。</font><font>事实上，鉴于这一事实</font></font><code>th:with</code><font><font>具有较高的</font></font><code>precedence</code><font><font>比</font></font><code>th:text</code><font><font>，我们可以解决这一切的</font></font><code>span</code><font><font>标签：</font></font>
            </p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                    class="token punctuation">&gt;</span></span><font></font>
  Today is: <font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
          class="token attr-name"><span class="token namespace">th:</span>with</span><span
          class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>df<span class="token punctuation">=</span>#{date.format}<span
          class="token punctuation">"</span></span>
        <span class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span
              class="token punctuation">"</span>${#calendars.format(today,df)}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>13 February 2011<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>你可能会想：优先级？</font><font>我们还没有说过！</font><font>那么，别担心，因为这正是下一章的内容。</font></font></p>
        </section>
        <section class="level1" id="attribute-precedence">
            <h1><font><font>10属性优先</font></font></h1>
            <p><font><font>当您</font></font><code>th:*</code><font><font>在同一个标​​签中</font><font>写入多个</font><font>属性</font><font>时会发生什么</font><font>？</font><font>例如：</font></font>
            </p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>ul</span><span
                    class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span
          class="token attr-name"><span class="token namespace">th:</span>each</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>item : ${items}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>text</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>${item.description}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Item description here...<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>li</span><span
                        class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>我们期望该</font></font><code>th:each</code><font><font>属性在之前执行，</font></font><code>th:text</code><font><font>以便获得我们想要的结果，但是鉴于HTML
                / XML标准对标签中的属性的顺序没有任何意义，</font></font><em><font><font>优先级</font></font></em><font><font>必须在属性本身中建立机制，以确保这将按预期工作。</font></font>
            </p>
            <p><font><font>所以，所有的Thymeleaf属性定义一个数字优先级，它确定在标签中执行它们的顺序。</font><font>这个订单是：</font></font></p>
            <div class="table-scroller">
                <table style="width:90%;">
                    <colgroup>
                        <col style="width: 11%">
                        <col style="width: 48%">
                        <col style="width: 30%">
                    </colgroup>
                    <thead>
                    <tr class="header">
                        <th style="text-align: left;"><font><font>订购</font></font></th>
                        <th style="text-align: left;"><font><font>特征</font></font></th>
                        <th style="text-align: left;"><font><font>属性</font></font></th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="odd">
                        <td style="text-align: left;"><font><font>1</font></font></td>
                        <td style="text-align: left;"><font><font>片段包含</font></font></td>
                        <td style="text-align: left;"><code>th:insert</code><br>
                            <code>th:replace</code></td>
                    </tr>
                    <tr class="even">
                        <td style="text-align: left;"><font><font>2</font></font></td>
                        <td style="text-align: left;"><font><font>片段迭代</font></font></td>
                        <td style="text-align: left;"><code>th:each</code></td>
                    </tr>
                    <tr class="odd">
                        <td style="text-align: left;"><font><font>3</font></font></td>
                        <td style="text-align: left;"><font><font>有条件的评估</font></font></td>
                        <td style="text-align: left;"><code>th:if</code><br>
                            <code>th:unless</code><br>
                            <code>th:switch</code><br>
                            <code>th:case</code></td>
                    </tr>
                    <tr class="even">
                        <td style="text-align: left;"><font><font>4</font></font></td>
                        <td style="text-align: left;"><font><font>局部变量定义</font></font></td>
                        <td style="text-align: left;"><code>th:object</code><br>
                            <code>th:with</code></td>
                    </tr>
                    <tr class="odd">
                        <td style="text-align: left;"><font><font>5</font></font></td>
                        <td style="text-align: left;"><font><font>一般属性修改</font></font></td>
                        <td style="text-align: left;"><code>th:attr</code><br>
                            <code>th:attrprepend</code><br>
                            <code>th:attrappend</code></td>
                    </tr>
                    <tr class="even">
                        <td style="text-align: left;"><font><font>6</font></font></td>
                        <td style="text-align: left;"><font><font>具体属性修改</font></font></td>
                        <td style="text-align: left;"><code>th:value</code><br>
                            <code>th:href</code><br>
                            <code>th:src</code><br>
                            <code>...</code></td>
                    </tr>
                    <tr class="odd">
                        <td style="text-align: left;"><font><font>7</font></font></td>
                        <td style="text-align: left;"><font><font>文本（标签体修改）</font></font></td>
                        <td style="text-align: left;"><code>th:text</code><br>
                            <code>th:utext</code></td>
                    </tr>
                    <tr class="even">
                        <td style="text-align: left;"><font><font>8</font></font></td>
                        <td style="text-align: left;"><font><font>片段规范</font></font></td>
                        <td style="text-align: left;"><code>th:fragment</code></td>
                    </tr>
                    <tr class="odd">
                        <td style="text-align: left;"><font><font>9</font></font></td>
                        <td style="text-align: left;"><font><font>片段去除</font></font></td>
                        <td style="text-align: left;"><code>th:remove</code></td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <p><font><font>这个优先机制意味着如果属性位置被反转，上述迭代片段将给出完全相同的结果（尽管它的可读性稍差）：</font></font></p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>ul</span><span
                    class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span
          class="token attr-name"><span class="token namespace">th:</span>text</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${item.description}<span
          class="token punctuation">"</span></span> <span class="token attr-name"><span
          class="token namespace">th:</span>each</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>item : ${items}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Item description here...<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>li</span><span
                        class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span
        class="token punctuation">&gt;</span></span></code></pre>
        </section>
        <section class="level1" id="comments-and-blocks">
            <h1><font><font>11评论和块</font></font></h1>
            <section class="level2" id="standard-htmlxml-comments">
                <h2><font><font>11.1。</font><font>标准HTML / XML注释</font></font></h2>
                <p><font><font>标准的HTML / XML注释</font></font><code>&lt;!-- ... --&gt;</code><font><font>可以在Thymeleaf模板的任何地方使用。</font><font>这些评论中的任何内容都不会被Thymeleaf处理，并将逐字复制到结果中：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token comment"
                                                                                 spellcheck="true">&lt;!-- User info follows --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
        class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span>${...}<span class="token punctuation">"</span></span><span
        class="token punctuation">&gt;</span></span><font></font>
  ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="thymeleaf-parser-level-comment-blocks">
                <h2><font><font>11.2。</font><font>Thymeleaf解析器级注释块</font></font></h2>
                <p><font><font>解析器级注释块是当Thymeleaf解析时将简单地从模板中删除的代码。</font><font>他们看起来像这样：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token comment"
                                                                                 spellcheck="true">&lt;!--/* This code will be removed at Thymeleaf parsing time! */--&gt;</span></code></pre>
                <p><font><font>Thymeleaf将删除一切与</font></font><code>&lt;!--/*</code><font><font>和</font></font><code>*/--&gt;</code><font><font>，所以这些注释块也可以用于显示当模板是静态开放代码，知道当Thymeleaf处理它，它都将被删除：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token comment"
                                                                                 spellcheck="true">&lt;!--/*--&gt;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span
          class="token punctuation">&gt;</span></span><font></font>
     you can see me only before Thymeleaf processes me!<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
          class="token punctuation">&gt;</span></span>
<span class="token comment" spellcheck="true">&lt;!--*/--&gt;</span></code></pre>
                <p><font><font>这可能非常方便的原型表与很多的</font></font><code>&lt;tr&gt;</code><font><font>，例如：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
           class="token attr-name"><span class="token namespace">th:</span>each</span><span
           class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>x : ${xs}<span
           class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
     ...<font></font>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
           class="token punctuation">&gt;</span></span>
   <span class="token comment" spellcheck="true">&lt;!--/*--&gt;</span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
           class="token punctuation">&gt;</span></span><font></font>
     ...<font></font>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
           class="token punctuation">&gt;</span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
           class="token punctuation">&gt;</span></span><font></font>
     ...<font></font>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
           class="token punctuation">&gt;</span></span>
   <span class="token comment" spellcheck="true">&lt;!--*/--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
            </section>
            <section class="level2" id="thymeleaf-prototype-only-comment-blocks">
                <h2><font><font>11.3。</font><font>Thymeleaf原型只有评论块</font></font></h2>
                <p><font><font>当模板静态打开（即原型））时，Thymeleaf允许定义标记为注释的特殊注释块，但在执行模板时，Thymeleaf被认为是正常的标记。</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span><span
                        class="token punctuation">&gt;</span></span>hello!<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>
<span class="token comment" spellcheck="true">&lt;!--/*/
  &lt;div th:text="${...}"&gt;
    ...
  &lt;/div&gt;
/*/--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
        class="token punctuation">&gt;</span></span>goodbye!<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>Thymeleaf的解析系统将简单地删除</font></font><code>&lt;!--/*/</code><font><font>和</font></font><code>/*/--&gt;</code><font><font>标记，而不是其内容，因此将被遗弃。</font><font>所以当执行模板时，Thymeleaf实际上会看到这样的：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span><span
                        class="token punctuation">&gt;</span></span>hello!<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span><font></font>
 <font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
          class="token attr-name"><span class="token namespace">th:</span>text</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${...}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
          class="token punctuation">&gt;</span></span><font></font>
 <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span
        class="token punctuation">&gt;</span></span>goodbye!<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>与解析器级注释块一样，此功能与方言无关。</font></font></p>
            </section>
            <section class="level2" id="synthetic-thblock-tag">
                <h2><font><font>11.4。</font><font>合成</font></font><code>th:block</code><font><font>标签</font></font></h2>
                <p>
                    <font><font>标准方言中包含的Thymeleaf唯一元素处理器（不是属性）是</font></font><code>th:block</code><font><font>。</font></font>
                </p>
                <p><code>th:block</code><font><font>是一个属性容器，允许模板开发人员指定他们想要的任何属性。</font><font>Thymeleaf将执行这些属性，然后简单地制作块，而不是其内容消失。</font></font>
                </p>
                <p><font><font>所以它可能是有用的，例如，当创建</font></font><code>&lt;tr&gt;</code><font><font>每个元素</font><font>需要多个迭代表时</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span
          class="token namespace">th:</span>block</span> <span class="token attr-name"><span
          class="token namespace">th:</span>each</span><span class="token attr-value"><span
          class="token punctuation">=</span><span class="token punctuation">"</span>user : ${users}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${user.login}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${user.name}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">colspan</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>2<span
                class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${user.address}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span
          class="token namespace">th:</span>block</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>当与原型注释块组合使用时尤其有用：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>table</span><span
                        class="token punctuation">&gt;</span></span>
    <span class="token comment" spellcheck="true">&lt;!--/*/ &lt;th:block th:each="user : ${users}"&gt; /*/--&gt;</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${user.login}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${user.name}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">colspan</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>2<span
                class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${user.address}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
            class="token punctuation">&gt;</span></span>
    <span class="token comment" spellcheck="true">&lt;!--/*/ &lt;/th:block&gt; /*/--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>注意这个解决方案如何允许模板是有效的HTML（不需要在其中添加禁止</font></font><code>&lt;div&gt;</code><font><font>块</font></font><code>&lt;table&gt;</code><font><font>），并且仍然可以在浏览器中作为原型静态打开！</font></font>
                </p>
            </section>
        </section>
        <section class="level1" id="inlining">
            <h1><font><font>12内联</font></font></h1>
            <section class="level2" id="expression-inlining">
                <h2><font><font>12.1表达式内联</font></font></h2>
                <p>
                    <font><font>虽然标准方言使我们能够使用标签属性来做几乎所有的事情，但是有些情况下我们更喜欢将表达式直接写入我们的HTML文本。</font><font>例如，我们可以喜欢写这个：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>Hello, [[${session.user.name}]]!<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>...而不是这样：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>Hello, <span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${session.user.name}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Sebastian<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span>!<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>表达式</font></font><code>[[...]]</code><font><font>或被认为</font></font><code>[(...)]</code><font><font>是</font></font><strong><font><font>内切表达式</font></font></strong><font><font>在Thymeleaf中，并且在它们之内，我们可以使用任何一种在一个</font></font><code>th:text</code><font><font>或</font><font>一个属性中也是有效的</font></font><code>th:utext</code><font><font>表达式。</font></font>
                </p>
                <p><font><font>请注意，虽然</font></font><code>[[...]]</code><font><font>对应于</font></font><code>th:text</code><font><font>（即结果将被</font></font><em><font><font>HTML转义</font></font></em><font><font>），</font></font><code>[(...)]</code><font><font>但对应于</font></font><code>th:utext</code><font><font>并且不会执行任何HTML转义。</font><font>所以用一个变量，如</font></font><code>msg
                    = 'This is &lt;b&gt;great!&lt;/b&gt;'</code><font><font>给定这个片段：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>The message is "[(${msg})]"<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>结果将使这些</font></font><code>&lt;b&gt;</code><font><font>标签不被转义，所以：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>The message is "This is <span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;</span>b</span><span class="token punctuation">&gt;</span></span>great!<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>b</span><span class="token punctuation">&gt;</span></span>"<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>而如果逃脱像：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>The message is "[[${msg}]]"<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>结果将被HTML转义：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span>The message is "This is <span class="token entity"
                                                                                                  title="<">&amp;lt;</span>b<span
                        class="token entity" title=">">&amp;gt;</span>great!<span class="token entity" title="<">&amp;lt;</span>/b<span
                        class="token entity" title=">">&amp;gt;</span>"<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>请注意，</font></font><strong><font><font>默认情况下</font></font></strong><font><font>，</font><strong><font>文本内联</font></strong><font>在我们的标记中的每个标签的正文中</font><strong><font>都是活动的</font></strong><font>，而不是标签本身，因此我们无法做到这一点。</font></font>
                </p>
                <section class="level3" id="inlining-vs-natural-templates">
                    <h3><font><font>内联与自然模板</font></font></h3>
                    <p>
                        <font><font>如果您来自其他模板引擎，其中输出文本的方式是常规，您可能会问：</font></font><em><font><font>为什么我们从一开始就不这样做？</font><font>它比所有这些</font></font></em>
                        <font><em><font>属性</font></em><em><font>代码少</font></em></font><code>th:text</code>
                        <em><font><font>！</font></font></em></p>
                    <p><font><font>那么在这里要小心，因为虽然你可能会发现内联非常有趣，但是您应该永远记住，当您静态打开HTML文件时，内嵌的表达式将逐字显示在HTML文件中，因此您可能无法将其用作设计原型再说了！</font></font>
                    </p>
                    <p><font><font>浏览器如何静态显示我们的代码段，而不使用内联...</font></font></p>
                    <pre><code>Hello, Sebastian!</code></pre>
                    <p><font><font>...并使用它...</font></font></p>
                    <pre><code>Hello, [[${session.user.name}]]!</code></pre>
                    <p><font><font>...在设计有用性方面很清楚。</font></font></p>
                </section>
                <section class="level3" id="disabling-inlining">
                    <h3><font><font>禁用内联</font></font></h3>
                    <p>
                        <font><font>这个机制可以被禁用，因为实际上可能会出现我们希望输出</font></font><code>[[...]]</code><font><font>或</font></font><code>[(...)]</code><font><font>序列而不将内容作为表达式处理的场合。</font><font>为此，我们将使用</font></font><code>th:inline="none"</code><font><font>：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>none<span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span>A double array looks like this: [[1, 2, 3], [4, 5]]!<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>这将导致：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                            class="token punctuation">&gt;</span></span>A double array looks like this: [[1, 2, 3], [4, 5]]!<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span></code></pre>
                </section>
            </section>
            <section class="level2" id="text-inlining">
                <h2><font><font>12.2文本内联</font></font></h2>
                <p>
                    <em><font><font>文本内联</font></font></em><font><font>非常类似于</font><font>我们刚刚看到</font><font>的</font></font><em><font><font>表达式内联</font></font></em><font><font>功能，但它实际上增加了更多的功能。</font><font>必须明确地启用它</font></font><code>th:inline="text"</code><font><font>。</font></font>
                </p>
                <p>
                    <font><font>文本内联不仅允许我们使用</font><font>我们刚刚看到</font><font>的相同的</font></font><em><font><font>内嵌表达式</font></font></em><font><font>，但实际上处理</font></font><em><font><font>标签体</font></font></em><font><font>就像在</font></font><code>TEXT</code><font><font>模板模式下</font><font>处理</font><font>模板一样，这使我们能够执行基于文本的模板逻辑（不仅仅是输出表达式）。</font></font>
                </p>
                <p>
                    <font><font>我们将在下一章中看到关于</font></font><em><font><font>文本模板模式的更多信息</font></font></em><font><font>。</font></font>
                </p>
            </section>
            <section class="level2" id="javascript-inlining">
                <h2><font><font>12.3 JavaScript内联</font></font></h2>
                <p><font><font>JavaScript内联允许</font></font><code>&lt;script&gt;</code><font><font>在</font></font><code>HTML</code><font><font>模板模板</font><font>中正在处理的</font><font>模板</font><font>中</font><font>更好地集成JavaScript </font><font>块</font><font>。</font></font>
                </p>
                <p>
                    <font><font>与</font></font><em><font><font>文本内联一样</font></font></em><font><font>，这实际上等同于处理脚本内容，就像它们是</font></font><code>JAVASCRIPT</code><font><font>模板模板</font><font>中的</font><font>模板一样，因此</font></font><em><font><font>文本模板模式的</font></font></em><font><font>所有</font><em><font>功能</font></em><font>（见下一章）将在手。</font><font>然而，在本节中，我们将重点介绍如何使用它将我们的Thymeleaf表达式的输出添加到我们的JavaScript块中。</font></font>
                </p>
                <p>
                    <font><font>必须使用</font></font><code>th:inline="javascript"</code><font><font>以下</font><font>方式显式启用此模式</font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>javascript<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var username = [[${session.user.name}]];<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这将导致：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>javascript<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var username = "Sebastian \"Fruity\" Applejuice";<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>以上代码中要注意的两个重要事项：</font></font></p>
                <p><em><font><font>首先</font></font></em><font><font>，JavaScript内联函数不仅会输出所需的文本，还可以使用引号和JavaScript来包含其中的内容，以便将表达式结果作为一个</font></font><strong><font><font>格式良好的JavaScript文字</font></font></strong><font><font>输出</font><font>。</font></font>
                </p>
                <p>
                    <em><font><font>其次</font></font></em><font><font>，这是因为我们输出</font></font><code>${session.user.name}</code><font><font>表达式作为</font></font><strong><font><font>转义</font></font></strong><font><font>，即使用双括号表达式：</font></font><code>[[${session.user.name}]]</code><font><font>。</font><font>如果我们使用</font></font><em><font><font>unescaped，</font></font></em><font><font>像：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>javascript<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var username = [(${session.user.name})];<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>结果将如下所示：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>javascript<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var username = Sebastian "Fruity" Applejuice;<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>...这是格式错误的JavaScript代码。</font><font>但是，如果我们通过附加内联表达式来构建脚本的一部分，那么输出一些未转义的东西可能就是我们需要的，所以手边有这个工具是很好的。</font></font>
                </p>
                <section class="level3" id="javascript-natural-templates">
                    <h3><font><font>JavaScript自然模板</font></font></h3>
                    <p><font><font>所提到的</font></font><em><font><font>智能</font></font></em><font><font>
                        JavaScript的内联机制的远不止仅仅将一个特定的JavaScript转义和输出表达式的结果是有效的文字更远。</font></font></p>
                    <p><font><font>例如，我们可以在JavaScript注释中包含（转义）内联表达式，如：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>javascript<span
                            class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var username = /*[[${session.user.name}]]*/ "Gertrud Kiwifruit";<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>而Thymeleaf将忽略</font></font><em><font><font>在注释之后和分号</font></font></em><font><font>（在这种情况下</font></font><code>'Gertrud
                        Kiwifruit'</code><font><font>）</font><em><font>之前写过的所有内容</font></em><font>，因此执行此操作的结果将与我们不使用包装注释时完全相同：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>javascript<span
                            class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var username = "Sebastian \"Fruity\" Applejuice";<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>但是请仔细查看原始模板代码：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>javascript<span
                            class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var username = /*[[${session.user.name}]]*/ "Gertrud Kiwifruit";<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p>
                        <font><font>注意这是如何</font></font><strong><font><font>有效的JavaScript</font></font></strong><font><font>代码。</font><font>当您以静态方式打开模板文件（不在服务器上执行）时，它将完全执行。</font></font>
                    </p>
                    <p><font><font>所以我们在这里是一种方法来做</font></font><strong><font><font>JavaScript自然模板</font></font></strong><font><font>！</font></font>
                    </p>
                </section>
                <section class="level3" id="advanced-inlined-evaluation-and-javascript-serialization">
                    <h3><font><font>高级内联评估和JavaScript序列化</font></font></h3>
                    <p><font><font>关于JavaScript内联的一个重要的事情是，这个表达式的评估是智能的，不限于字符串。</font><font>Thymeleaf将正确地写入JavaScript语法中的以下几种对象：</font></font>
                    </p>
                    <ul>
                        <li><font><font>弦</font></font></li>
                        <li><font><font>数字</font></font></li>
                        <li><font><font>布尔值</font></font></li>
                        <li><font><font>数组</font></font></li>
                        <li><font><font>集合</font></font></li>
                        <li><font><font>地图</font></font></li>
                        <li>
                            <font><font>豆（具有</font></font><em><font><font>吸气剂</font></font></em><font><font>和</font></font><em><font><font>固定</font></font></em><font><em><font>剂</font></em><font>方法的</font><font>物体</font><font>）</font></font>
                        </li>
                    </ul>
                    <p><font><font>例如，如果我们有以下代码：</font></font></p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>javascript<span
                            class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var user = /*[[${session.user}]]*/ null;<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>该</font></font><code>${session.user}</code><font><font>表达式将评估为一个</font></font><code>User</code><font><font>对象，并且Thymeleaf将正确地将其转换为JavaScript语法：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>script</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>javascript<span
                            class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
    var user = {"age":null,"firstName":"John","lastName":"Apricot",<font></font>
                "name":"John Apricot","nationality":"Antarctica"};<font></font>
    ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                    <p><font><font>这种JavaScript序列化的方式是通过接口的</font></font><code>org.thymeleaf.standard.serializer.IStandardJavaScriptSerializer</code><font><font>实现，可以</font></font><code>StandardDialect</code><font><font>在模板引擎使用</font><font>的实例中</font><font>进行配置。</font></font>
                    </p>
                    <p><font><font>该JS序列化机制的默认实现将在类路径中查找</font></font><a
                            href="https://github.com/FasterXML/jackson"><font><font>Jackson库</font></font></a><font><font>，如果存在，将使用它。</font><font>如果没有，它将应用一个内置的序列化机制，涵盖大多数场景的需求，并产生类似的结果（但不太灵活）。</font></font>
                    </p>
                </section>
            </section>
            <section class="level2" id="css-inlining">
                <h2><font><font>12.4 CSS内联</font></font></h2>
                <p>
                    <font><font>Thymeleaf还允许在CSS </font></font><code>&lt;style&gt;</code><font><font>标签中</font><font>使用内联</font><font>，例如：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>style</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>css<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
  ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>例如，假设我们有两个变量设置为两个不同的</font></font><code>String</code><font><font>值：</font></font></p>
                <pre><code>classname = 'main elems'<font></font>
align = 'center'</code></pre>
                <p><font><font>我们可以使用它们，就像：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>style</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>css<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
    .[[${classname}]] {<font></font>
      text-align: [[${align}]];<font></font>
    }<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>结果是：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>style</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>css<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
    .main\ elems {<font></font>
      text-align: center;<font></font>
    }<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>请注意，CSS内联是否也具有一些</font></font><em><font><font>智慧</font></font></em><font><font>，就像JavaScript的一样。</font><font>具体来说，通过</font></font><em><font><font>转义</font></font></em><font><font>表达式输出的</font><font>表达式</font></font><code>[[${classname}]]</code><font><font>将被转义为</font></font><strong><font><font>CSS标识符</font></font></strong><font><font>。</font><font>这就是为什么我们</font></font><code>classname
                    = 'main elems'</code><font><font>已经转化为</font></font><code>main\
                    elems</code><font><font>上面的代码片段。</font></font></p>
                <section class="level3" id="advanced-features-css-natural-templates-etc.">
                    <h3><font><font>高级功能：CSS自然模板等</font></font></h3>
                    <p>
                        <font><font>以与JavaScript之前解释的相同的方式，CSS内联还允许我们的</font></font><code>&lt;style&gt;</code><font><font>标签静态和动态地工作，即</font><font>通过在注释中包含内联表达式</font><font>作为</font></font><strong><font><font>CSS自然模板</font></font></strong><font><font>。</font><font>看到：</font></font>
                    </p>
                    <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>style</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>inline</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>css<span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span><font></font>
    .main\ elems {<font></font>
      text-align: /*[[${align}]]*/ left;<font></font>
    }<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                </section>
            </section>
        </section>
        <section class="level1" id="textual-template-modes">
            <h1><font><font>13文本模板模式</font></font></h1>
            <section class="level2" id="textual-syntax">
                <h2><font><font>13.1文本语法</font></font></h2>
                <p><font><font>在Thymeleaf的三种</font></font><em><font><font>模板模式</font></font></em><font><font>被认为是</font></font><strong><font><font>文字</font></font></strong><font><font>：</font></font><code>TEXT</code><font><font>，</font></font><code>JAVASCRIPT</code><font><font>和</font></font><code>CSS</code><font><font>。</font><font>这将它们与标记模板模式区分开来：</font></font><code>HTML</code><font><font>和</font></font><code>XML</code><font><font>。</font></font>
                </p>
                <p>
                    <font></font><em><font><font>文本</font></font></em><font><font>模板模式和标记模式</font><font>之间的关键区别</font><font>在于，在文本模板中，没有标签以属性的形式插入逻辑，因此我们必须依赖其他机制。</font></font>
                </p>
                <p><font><font>这些机制的第一个也是最基本的是</font></font><strong><font><font>内联</font></font></strong><font><font>，我们在前一章已经详细介绍</font><font>了这些机制</font><font>。</font><font>内联语法是以文本模板模式输出表达式结果的最简单方法，因此这是一个完全有效的文本电子邮件模板。</font></font>
                </p>
                <pre><code>  Dear [(${name})],<font></font>
<font></font>
  Please find attached the results of the report you requested<font></font>
  with name "[(${report.name})]".<font></font>
<font></font>
  Sincerely,<font></font>
    The Reporter.</code></pre>
                <p>
                    <font><font>即使没有标签，上面的示例是一个完整有效的Thymeleaf模板，可以在</font></font><code>TEXT</code><font><font>模板模式下</font><font>执行</font><font>。</font></font>
                </p>
                <p><font><font>但是为了包含比单纯的</font></font><em><font><font>输出表达式</font></font></em><font><font>更复杂的逻辑</font><font>，我们需要一个新的基于非标记的语法：</font></font>
                </p>
                <pre><code>[# th:each="item : ${items}"]<font></font>
  - [(${item})]<font></font>
[/]</code></pre>
                <p><font><font>其实是</font></font><em><font><font>精简</font></font></em><font><font>版的更冗长：</font></font>
                </p>
                <pre><code>[#th:block th:each="item : ${items}"]<font></font>
  - [#th:block th:utext="${item}" /]<font></font>
[/th:block]</code></pre>
                <p><font><font>注意这个新语法是如何基于声明为</font></font><code>[#element ...]</code><font><font>代替的</font><font>元素（即可处理的标签）</font></font><code>&lt;element
                    ...&gt;</code><font><font>。</font><font>元素的开放状态</font></font><code>[#element ...]</code><font><font>和关闭状态类似</font></font><code>[/element]</code><font><font>，独立的标签可以通过最小化开放元素</font></font><code>/</code><font><font>的方式</font><font>来声明</font><font>，其方式几乎相当于XML标签：</font></font><code>[#element
                    ... /]</code><font><font>。</font></font></p>
                <p><font><font>标准方言只包含以下这些元素之一的处理器：已知的</font></font><code>th:block</code><font><font>，尽管我们可以用我们的方言来扩展它，并以通常的方式创建新的元素。</font><font>此外，</font></font><code>th:block</code><font><font>element（</font></font><code>[#th:block
                    ...] ... [/th:block]</code><font><font>）被允许缩写为空字符串（</font></font><code>[# ...] ...
                    [/]</code><font><font>），因此上述块实际上等同于：</font></font></p>
                <pre><code>[# th:each="item : ${items}"]<font></font>
  - [# th:utext="${item}" /]<font></font>
[/]</code></pre>
                <p><font><font>给定</font></font><code>[# th:utext="${item}"
                    /]</code><font><font>相当于一个</font></font><em><font><font>内联的非转义表达式</font></font></em><font><font>，我们可以使用它来减少代码。</font><font>因此，我们结束了上面看到的第一个代码片段：</font></font>
                </p>
                <pre><code>[# th:each="item : ${items}"]<font></font>
  - [(${item})]<font></font>
[/]</code></pre>
                <p>
                    <font><font>请注意，</font></font><em><font><font>文本语法需要完整的元素平衡（没有未封闭的标签）和引用的属性</font></font></em><font><font>
                    - 它比HTML样式更多的XML风格。</font></font></p>
                <p>
                    <font><font>我们来看一个更完整的</font></font><code>TEXT</code><font><font>模板</font><font>示例</font><font>，一个</font></font><em><font><font>纯文本</font></font></em><font><font>电子邮件模板：</font></font>
                </p>
                <pre><code>Dear [(${customer.name})],<font></font>
<font></font>
This is the list of our products:<font></font>
<font></font>
[# th:each="prod : ${products}"]<font></font>
   - [(${prod.name})]. Price: [(${prod.price})] EUR/kg<font></font>
[/]<font></font>
<font></font>
Thanks,<font></font>
  The Thymeleaf Shop</code></pre>
                <p><font><font>执行后，其结果可能是：</font></font></p>
                <pre><code>Dear Mary Ann Blueberry,<font></font>
<font></font>
This is the list of our products:<font></font>
<font></font>
   - Apricots. Price: 1.12 EUR/kg<font></font>
   - Bananas. Price: 1.78 EUR/kg<font></font>
   - Apples. Price: 0.85 EUR/kg<font></font>
   - Watermelon. Price: 1.91 EUR/kg<font></font>
<font></font>
Thanks,<font></font>
  The Thymeleaf Shop</code></pre>
                <p><font><font>另一个</font></font><code>JAVASCRIPT</code><font><font>模板模式中的一个</font><font>例子</font><font>，一个</font></font><code>greeter.js</code><font><font>文件，我们作为一个文本模板进行处理，我们从HTML页面调用哪个结果。</font><font>注意，这</font></font><em><font><font>不是</font></font></em><font></font><code>&lt;script&gt;</code><font><font>
                    HTML模板中的</font><font>一个</font><font>块，而是一个</font></font><code>.js</code><font><font>文件被自己处理为模板：</font></font>
                </p>
                <pre class="  language-javascript"><code
                        class="  language-javascript">var greeter = function() {<font></font>
<font></font>
    var username = [[${session.user.name}]];<font></font>
<font></font>
    [# th:each="salut : ${salutations}"]    <font></font>
      alert([[${salut}]] + " " + username);<font></font>
    [/]<font></font>
<font></font>
};</code></pre>
                <p><font><font>执行后，其结果可能是：</font></font></p>
                <pre class="  language-javascript"><code
                        class="  language-javascript">var greeter = function() {<font></font>
<font></font>
    var username = "Bertrand \"Crunchy\" Pear";<font></font>
<font></font>
      alert("Hello" + " " + username);<font></font>
      alert("Ol\u00E1" + " " + username);<font></font>
      alert("Hola" + " " + username);<font></font>
<font></font>
};</code></pre>
                <section class="level3" id="escaped-element-attributes">
                    <h3><font><font>转义的元素属性</font></font></h3>
                    <p>
                        <font><font>为了避免与可能以其他模式处理的模板的部分（例如，</font><font>模板</font></font><code>text</code><font><font>内嵌</font></font><code>HTML</code><font><font>模板）进行交互，Thymeleaf
                        3.0允许</font><font>转义</font><font>其</font></font><em><font><font>文本语法</font></font></em><font><font>中的元素中的属性</font><font>。</font><font>所以：</font></font>
                    </p>
                    <ul>
                        <li><font></font><code>TEXT</code><font><font>模板模式</font><font>中的</font><font>属性将被</font></font><em><font><font>HTML转义</font></font></em><font><font>。</font></font>
                        </li>
                        <li><font></font><code>JAVASCRIPT</code><font><font>模板模式</font><font>中的</font><font>属性将是</font></font><em><font><font>JavaScript未转义的</font></font></em><font><font>。</font></font>
                        </li>
                        <li>
                            <font></font><code>CSS</code><font><font>模板模式</font><font>中的</font><font>属性将被</font></font><em><font><font>CSS转义</font></font></em><font><font>。</font></font>
                        </li>
                    </ul>
                    <p><font><font>因此，这将是一个完全确定</font></font><code>TEXT</code><font><font>-模式模板（注意</font></font><code>&amp;gt;</code><font><font>）：</font></font>
                    </p>
                    <pre><code>  [# th:if="${120&amp;lt;user.age}"]<font></font>
     Congratulations!<font></font>
  [/]</code></pre>
                    <p><font><font>当然，这的</font></font><code>&amp;lt;</code><font><font>会使一个没有意义的</font></font><em><font><font>真正的文字</font></font></em><font><font>模板，但它是一个好主意，如果我们处理了一个HTML模板</font></font><code>th:inline="text"</code><font><font>包含上面的代码块，我们要确保我们的浏览器不采取</font></font><code>&lt;user.age</code><font><font>针对的名字当打开文件作为原型时打开标签。</font></font>
                    </p>
                </section>
            </section>
            <section class="level2" id="extensibility">
                <h2><font><font>13.2可扩展性</font></font></h2>
                <p>
                    <font><font>这种语法的一个优点是它与</font></font><em><font><font>标记</font></font></em><font><font>一样可扩展</font><font>。</font><font>开发人员仍然可以使用自定义元素和属性来定义自己的方言，为它们应用前缀（可选），然后在文本模板模式下使用它们：</font></font>
                </p>
                <pre><code>  [#myorg:dosomething myorg:importantattr="211"]some text[/myorg:dosomething]</code></pre>
            </section>
            <section class="level2" id="textual-prototype-only-comment-blocks-adding-code">
                <h2><font><font>13.3文本原型注释块：添加代码</font></font></h2>
                <p>
                    <font><font>在</font></font><code>JAVASCRIPT</code><font><font>和</font></font><code>CSS</code><font><font>模板模式（不适用于</font></font><code>TEXT</code><font><font>），允许包括一个特殊的注释语法之间的代码</font></font><code>/*[+...+]*/</code><font><font>，这样Thymeleaf会处理模板时自动取消注释这样的代码：</font></font>
                </p>
                <pre class="  language-javascript"><code class="  language-javascript">var x = 23;<font></font>
<font></font>
/*[+<font></font>
<font></font>
var msg  = "This is a working application";<font></font>
<font></font>
+]*/<font></font>
<font></font>
var f = function() {<font></font>
    ...</code></pre>
                <p><font><font>将被执行为：</font></font></p>
                <pre class="  language-javascript"><code class="  language-javascript">var x = 23;<font></font>
<font></font>
var msg  = "This is a working application";<font></font>
<font></font>
var f = function() {<font></font>
...</code></pre>
                <p><font><font>您可以在这些注释中包含表达式，并对它们进行评估：</font></font></p>
                <pre class="  language-javascript"><code class="  language-javascript">var x = 23;<font></font>
<font></font>
/*[+<font></font>
<font></font>
var msg  = "Hello, " + [[${session.user.name}]];<font></font>
<font></font>
+]*/<font></font>
<font></font>
var f = function() {<font></font>
...</code></pre>
            </section>
            <section class="level2" id="textual-parser-level-comment-blocks-removing-code">
                <h2><font><font>13.4文本解析器级注释块：删除代码</font></font></h2>
                <p>
                    <font><font>在类似于仅原型的注释块的方式，所有三个文本模板模式（</font></font><code>TEXT</code><font><font>，</font></font><code>JAVASCRIPT</code><font><font>和</font></font><code>CSS</code><font><font>）使其能够指示Thymeleaf特殊之间移除代码</font></font><code>/*[-
                    */</code><font><font>和</font></font><code>/* -]*/</code><font><font>标志，就像这样：</font></font></p>
                <pre class="  language-javascript"><code class="  language-javascript">var x = 23;<font></font>
<font></font>
/*[- */<font></font>
<font></font>
var msg  = "This is shown only when executed statically!";<font></font>
<font></font>
/* -]*/<font></font>
<font></font>
var f = function() {<font></font>
...</code></pre>
                <p><font><font>或者，在</font></font><code>TEXT</code><font><font>模式中：</font></font></p>
                <pre><code>...<font></font>
/*[- Note the user is obtained from the session, which must exist -]*/<font></font>
Welcome [(${session.user.name})]!<font></font>
...</code></pre>
            </section>
            <section class="level2" id="natural-javascript-and-css-templates">
                <h2><font><font>13.5自然的JavaScript和CSS模板</font></font></h2>
                <p><font><font>如前一章所示，JavaScript和CSS内联提供了在JavaScript / CSS注释中包含内置表达式的可能性，如：</font></font></p>
                <pre class="  language-javascript"><code class="  language-javascript">...<font></font>
var username = /*[[${session.user.name}]]*/ "Sebastian Lychee";<font></font>
...</code></pre>
                <p><font><font>...这是有效的JavaScript，一旦执行可能看起来像：</font></font></p>
                <pre class="  language-html"><code class="  language-html">...<font></font>
var username = "John Apricot";<font></font>
...</code></pre>
                <p>
                    <font><font>在注释中包含内联表达式的</font><font>同样的</font></font><em><font><font>技巧</font></font></em><font><font>实际上可以用于整个文本模式语法：</font></font>
                </p>
                <pre><code>  /*[# th:if="${user.admin}"]*/<font></font>
     alert('Welcome admin');<font></font>
  /*[/]*/</code></pre>
                <p><font><font>当模板静态打开时，将会显示上述代码中的警报 - 因为它是100％有效的JavaScript -
                    以及当用户是管理员时运行模板。</font><font>相当于：</font></font></p>
                <pre><code>  [# th:if="${user.admin}"]<font></font>
     alert('Welcome admin');<font></font>
  [/]</code></pre>
                <p><font><font>...这实际上是在模板解析期间转换初始版本的代码。</font></font></p>
                <p>
                    <font><font>请注意，注释中的包装元素不会</font></font><code>;</code><font><font>像内联的输出表达式那样</font><font>清除它们所在的行（直到</font><font>找到的行）。</font><font>该行为仅用于内联输出表达式。</font></font>
                </p>
                <p><font><font>所以Thymeleaf
                    3.0允许</font></font><strong><font><font>以自然模板的形式开发复杂的JavaScript脚本和CSS样式表</font></font></strong><font><font>，既可以作为</font></font><em><font><font>原型</font></font></em><font><font>，也可以作为</font></font><em><font><font>工作模板</font></font></em><font><font>。</font></font>
                </p>
            </section>
        </section>
        <section class="level1" id="some-more-pages-for-our-grocery">
            <h1><font><font>14我们的杂货店还有一些页面</font></font></h1>
            <p><font><font>现在我们知道很多关于使用Thymeleaf，我们可以在我们的网站上添加一些新的页面来进行订单管理。</font></font></p>
            <p><font><font>请注意，我们将专注于HTML代码，但如果要查看相应的控制器，可以查看捆绑的源代码。</font></font></p>
            <section class="level2" id="order-list">
                <h2><font><font>14.1订单</font></font></h2>
                <p>
                    <font><font>我们从创建订单列表页面开始</font></font><code>/WEB-INF/templates/order/list.html</code><font><font>：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span
        class="token attr-name"><span class="token namespace">xmlns:</span>th</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span><a href="http://www.thymeleaf.org"
                                                                                     rel="noreferrer"
                                                                                     style="cursor:help;display:inline !important;"
                                                                                     target="_blank">http://www.thymeleaf.org</a><span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
            class="token punctuation">&gt;</span></span>Good Thymes Virtual Grocery<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span
            class="token attr-name">http-equiv</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>Content-Type<span
            class="token punctuation">"</span></span> <span class="token attr-name">content</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/html; charset<span
            class="token punctuation">=</span>UTF-8<span class="token punctuation">"</span></span> <span
            class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
            class="token attr-name">rel</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>stylesheet<span
            class="token punctuation">"</span></span> <span class="token attr-name">type</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
            class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all<span
            class="token punctuation">"</span></span>
          <span class="token attr-name">href</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>../../../css/gtvg.css<span
                class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>@{/css/gtvg.css}<span class="token punctuation">"</span></span> <span
                class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span
            class="token punctuation">&gt;</span></span>Order list<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>h1</span><span
                            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>DATE<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>CUSTOMER<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>TOTAL<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
              class="token attr-name"><span class="token namespace">th:</span>each</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>o : ${orders}<span
              class="token punctuation">"</span></span> <span class="token attr-name"><span
              class="token namespace">th:</span>class</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>${oStat.odd}? <span
              class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${#calendars.format(o.date,<span class="token punctuation">'</span>dd/MMM/yyyy<span
                class="token punctuation">'</span>)}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>13 jan 2011<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${o.customer.name}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>Frederic Tomato<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${#aggregates.sum(o.orderLines.{purchasePrice * amount})}<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>23.32<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span
                class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
                  class="token attr-name">href</span><span class="token attr-value"><span
                  class="token punctuation">=</span><span class="token punctuation">"</span>details.html<span
                  class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                  class="token attr-value"><span class="token punctuation">=</span><span
                  class="token punctuation">"</span>@{/order/details(orderId<span class="token punctuation">=</span>${o.id})}<span
                  class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>view<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>../home.html<span class="token punctuation">"</span></span> <span
              class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>@{/}<span
              class="token punctuation">"</span></span><span
              class="token punctuation">&gt;</span></span>Return to home<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
            class="token punctuation">&gt;</span></span><font></font>
    <font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这里没有什么应该让我们惊讶，除了这一点的OGNL魔法：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${#aggregates.sum(o.orderLines.{purchasePrice * amount})}<span
                        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>23.32<span
                        class="token tag"><span class="token tag"><span
                        class="token punctuation">&lt;/</span>td</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>这样做的是，对于顺序中的每个订单行（</font></font><code>OrderLine</code><font><font>对象），将其</font></font><code>purchasePrice</code><font><font>和</font></font><code>amount</code><font><font>属性（通过调用相应的</font></font><code>getPurchasePrice()</code><font><font>和</font></font><code>getAmount()</code><font><font>方法）</font><font>相乘</font><font>并将</font><font>结果返回到数字列表中，稍后由</font></font><code>#aggregates.sum(...)</code><font><font>函数</font><font>聚合</font><font>以获得订单总数价钱。</font></font>
                </p>
                <p><font><font>你必须爱上OGNL的力量。</font></font></p>
            </section>
            <section class="level2" id="order-details">
                <h2><font><font>14.2订单明细</font></font></h2>
                <p><font><font>现在对于订单详细信息页面，我们将大量使用星号语法：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span><font></font>
<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span
        class="token attr-name"><span class="token namespace">xmlns:</span>th</span><span class="token attr-value"><span
        class="token punctuation">=</span><span class="token punctuation">"</span><a href="http://www.thymeleaf.org"
                                                                                     rel="noreferrer"
                                                                                     style="cursor:help;display:inline !important;"
                                                                                     target="_blank">http://www.thymeleaf.org</a><span
        class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span
            class="token punctuation">&gt;</span></span>Good Thymes Virtual Grocery<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>title</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span
            class="token attr-name">http-equiv</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>Content-Type<span
            class="token punctuation">"</span></span> <span class="token attr-name">content</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/html; charset<span
            class="token punctuation">=</span>UTF-8<span class="token punctuation">"</span></span> <span
            class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span
            class="token attr-name">rel</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>stylesheet<span
            class="token punctuation">"</span></span> <span class="token attr-name">type</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/css<span
            class="token punctuation">"</span></span> <span class="token attr-name">media</span><span
            class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all<span
            class="token punctuation">"</span></span>
          <span class="token attr-name">href</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>../../../css/gtvg.css<span
                class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>href</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>@{/css/gtvg.css}<span class="token punctuation">"</span></span> <span
                class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span> <span
          class="token attr-name"><span class="token namespace">th:</span>object</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>${order}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span
            class="token punctuation">&gt;</span></span>Order details<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
              class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>b</span><span
                            class="token punctuation">&gt;</span></span>Code:<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>b</span><span
                            class="token punctuation">&gt;</span></span> <span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>text</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>*{id}<span class="token punctuation">"</span></span><span
                            class="token punctuation">&gt;</span></span>99<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                            class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>b</span><span
                class="token punctuation">&gt;</span></span>Date:<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>b</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>*{#calendars.format(date,<span class="token punctuation">'</span>dd MMM yyyy<span
                class="token punctuation">'</span>)}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>13 jan 2011<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
            class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span
            class="token punctuation">&gt;</span></span>Customer<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>h2</span><span
                            class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
            class="token attr-name"><span class="token namespace">th:</span>object</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>*{customer}<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
              class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>b</span><span
                            class="token punctuation">&gt;</span></span>Name:<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>b</span><span
                            class="token punctuation">&gt;</span></span> <span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>text</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>*{name}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Frederic Tomato<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span><span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>b</span><span
                class="token punctuation">&gt;</span></span>Since:<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>b</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>*{#calendars.format(customerSince,<span
                class="token punctuation">'</span>dd MMM yyyy<span class="token punctuation">'</span>)}<span
                class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>1 jan 2011<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span
            class="token punctuation">&gt;</span></span>Products<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>h2</span><span
                            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>PRODUCT<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>AMOUNT<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>th</span><span
                class="token punctuation">&gt;</span></span>PURCHASE PRICE<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>th</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
              class="token attr-name"><span class="token namespace">th:</span>each</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>ol,row : *{orderLines}<span
              class="token punctuation">"</span></span> <span class="token attr-name"><span
              class="token namespace">th:</span>class</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>${row.odd}? <span
              class="token punctuation">'</span>odd<span class="token punctuation">'</span><span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${ol.product.name}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>Strawberries<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${ol.amount}<span class="token punctuation">"</span></span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>number<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>3<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${ol.purchasePrice}<span
                class="token punctuation">"</span></span> <span class="token attr-name">class</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>number<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>23.32<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
            class="token punctuation">&gt;</span></span><font></font>
<font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>b</span><span
              class="token punctuation">&gt;</span></span>TOTAL:<span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>b</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
              class="token attr-name"><span class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>*{#aggregates.sum(orderLines.{purchasePrice * amount})}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>35.23<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
            class="token punctuation">&gt;</span></span><font></font>
  <font></font>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span
              class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span
              class="token punctuation">"</span>list.html<span class="token punctuation">"</span></span> <span
              class="token attr-name"><span class="token namespace">th:</span>href</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>@{/order/list}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Return to order list<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>a</span><span
                            class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
            class="token punctuation">&gt;</span></span><font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span><font></font>
  <font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>这里没有太多的新意，除了这个嵌套的对象选择：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>body</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>object</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${order}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span><font></font>
<font></font>
  ...<font></font>
<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
          class="token attr-name"><span class="token namespace">th:</span>object</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>*{customer}<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span
            class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;</span>b</span><span
                            class="token punctuation">&gt;</span></span>Name:<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>b</span><span
                            class="token punctuation">&gt;</span></span> <span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                            class="token attr-name"><span class="token namespace">th:</span>text</span><span
                            class="token attr-value"><span class="token punctuation">=</span><span
                            class="token punctuation">"</span>*{name}<span
                            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Frederic Tomato<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span><span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>p</span><span
                            class="token punctuation">&gt;</span></span><font></font>
    ...<font></font>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span
          class="token punctuation">&gt;</span></span><font></font>
<font></font>
  ...<font></font>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>... </font></font><code>*{name}</code><font><font>等于：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>p</span><span
                        class="token punctuation">&gt;</span></span><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>b</span><span
                        class="token punctuation">&gt;</span></span>Name:<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>b</span><span
                        class="token punctuation">&gt;</span></span> <span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>span</span> <span
                        class="token attr-name"><span class="token namespace">th:</span>text</span><span
                        class="token attr-value"><span class="token punctuation">=</span><span
                        class="token punctuation">"</span>${order.customer.name}<span class="token punctuation">"</span></span><span
                        class="token punctuation">&gt;</span></span>Frederic Tomato<span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>span</span><span
                        class="token punctuation">&gt;</span></span><span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;/</span>p</span><span
                        class="token punctuation">&gt;</span></span></code></pre>
            </section>
        </section>
        <section class="level1" id="more-on-configuration">
            <h1><font><font>15更多配置</font></font></h1>
            <section class="level2" id="template-resolvers">
                <h2><font><font>15.1模板解析器</font></font></h2>
                <p><font><font>对于我们的Good Thymes Virtual
                    Grocery，我们选择了一种</font></font><code>ITemplateResolver</code><font><font>称为</font></font><code>ServletContextTemplateResolver</code><font><font>该方法的实现，可以让我们从Servlet上下文中获取资源。</font></font>
                </p>
                <p><font><font>除了让我们通过实施</font></font><code>ITemplateResolver,</code><font><font>Thymeleaf </font><font>创建我们自己的模板解析器的</font><font>能力包括四个实现开箱即用：</font></font>
                </p>
                <ul>
                    <li><p><code>org.thymeleaf.templateresolver.ClassLoaderTemplateResolver</code><font><font>，它将模板解析为类加载器资源，如：</font></font>
                    </p>
                        <pre class="  language-java"><code class="  language-java"><span
                                class="token keyword">return</span> Thread<span class="token punctuation">.</span><span
                                class="token function">currentThread</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">.</span><span
                                class="token function">getContextClassLoader</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">.</span><span
                                class="token function">getResourceAsStream</span><span
                                class="token punctuation">(</span>template<span class="token punctuation">)</span><span
                                class="token punctuation">;</span></code></pre>
                    </li>
                    <li><p><code>org.thymeleaf.templateresolver.FileTemplateResolver</code><font><font>，它将模板解析为文件系统中的文件，如：</font></font>
                    </p>
                        <pre class="  language-java"><code class="  language-java"><span
                                class="token keyword">return</span> <span class="token keyword">new</span> <span
                                class="token class-name">FileInputStream</span><span
                                class="token punctuation">(</span><span class="token keyword">new</span> <span
                                class="token class-name">File</span><span
                                class="token punctuation">(</span>template<span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    </li>
                    <li><p><code>org.thymeleaf.templateresolver.UrlTemplateResolver</code><font><font>，它将模板解析为URL（甚至非本地的），如：</font></font>
                    </p>
                        <pre class="  language-java"><code class="  language-java"><span
                                class="token keyword">return</span> <span class="token punctuation">(</span><span
                                class="token keyword">new</span> <span class="token class-name">URL</span><span
                                class="token punctuation">(</span>template<span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">.</span><span
                                class="token function">openStream</span><span class="token punctuation">(</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    </li>
                    <li><p>
                        <code>org.thymeleaf.templateresolver.StringTemplateResolver</code><font><font>，它直接解析</font><em><font>模板</font></em><font>，</font></font><code>String</code><font><font>指定为</font></font><code>template</code><font><font>（或</font></font><em><font><font>模板名称</font></font></em><font><font>，在这种情况下，这显然远远超过一个名称）：</font></font>
                    </p>
                        <pre class="  language-java"><code class="  language-java"><span
                                class="token keyword">return</span> <span class="token keyword">new</span> <span
                                class="token class-name">StringReader</span><span class="token punctuation">(</span>templateName<span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    </li>
                </ul>
                <p><font><font>所有预捆绑的</font></font><code>ITemplateResolver</code><font><font>实现允许相同的一组配置参数，其中包括：</font></font>
                </p>
                <ul>
                    <li><p><font><font>前缀和后缀（已经看到）：</font></font></p>
                        <pre class="  language-java"><code class="  language-java">templateResolver<span
                                class="token punctuation">.</span><span class="token function">setPrefix</span><span
                                class="token punctuation">(</span><span
                                class="token string">"/WEB-INF/templates/"</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span>
templateResolver<span class="token punctuation">.</span><span class="token function">setSuffix</span><span
                                    class="token punctuation">(</span><span class="token string">".html"</span><span
                                    class="token punctuation">)</span><span
                                    class="token punctuation">;</span></code></pre>
                    </li>
                    <li><p><font><font>允许使用不直接对应于文件名的模板名称的模板别名。</font><font>如果后缀/前缀和别名都存在，则在前缀/后缀之前应用别名：</font></font>
                    </p>
                        <pre class="  language-java"><code class="  language-java">templateResolver<span
                                class="token punctuation">.</span><span
                                class="token function">addTemplateAlias</span><span
                                class="token punctuation">(</span><span class="token string">"adminHome"</span><span
                                class="token punctuation">,</span><span
                                class="token string">"profiles/admin/home"</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span>
templateResolver<span class="token punctuation">.</span><span class="token function">setTemplateAliases</span><span
                                    class="token punctuation">(</span>aliasesMap<span class="token punctuation">)</span><span
                                    class="token punctuation">;</span></code></pre>
                    </li>
                    <li><p><font><font>读取模板时应用的编码：</font></font></p>
                        <pre class="  language-java"><code class="  language-java">templateResolver<span
                                class="token punctuation">.</span><span class="token function">setEncoding</span><span
                                class="token punctuation">(</span><span class="token string">"UTF-8"</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    </li>
                    <li><p><font><font>要使用的模板模式：</font></font></p>
                        <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                         spellcheck="true">// Default is HTML</span>
templateResolver<span class="token punctuation">.</span><span class="token function">setTemplateMode</span><span
                                    class="token punctuation">(</span><span class="token string">"XML"</span><span
                                    class="token punctuation">)</span><span
                                    class="token punctuation">;</span></code></pre>
                    </li>
                    <li><p><font><font>模板缓存的默认模式以及用于定义特定模板是否可缓存的模式：</font></font></p>
                        <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                         spellcheck="true">// Default is true</span>
templateResolver<span class="token punctuation">.</span><span class="token function">setCacheable</span><span
                                    class="token punctuation">(</span><span class="token boolean">false</span><span
                                    class="token punctuation">)</span><span class="token punctuation">;</span>
templateResolver<span class="token punctuation">.</span><span class="token function">getCacheablePatternSpec</span><span
                                    class="token punctuation">(</span><span class="token punctuation">)</span><span
                                    class="token punctuation">.</span><span
                                    class="token function">addPattern</span><span
                                    class="token punctuation">(</span><span class="token string">"/users/*"</span><span
                                    class="token punctuation">)</span><span
                                    class="token punctuation">;</span></code></pre>
                    </li>
                    <li><p><font><font>解析的模板缓存条目的TTL（以毫秒为单位）来源于此模板解析器。</font><font>如果未设置，则从缓存中删除条目的唯一方法将是LRU（超出缓存最大大小，条目是最早的）。</font></font>
                    </p>
                        <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                         spellcheck="true">// Default is no TTL (only LRU would remove entries)</span>
templateResolver<span class="token punctuation">.</span><span class="token function">setCacheTTLMs</span><span
                                    class="token punctuation">(</span>60000L<span
                                    class="token punctuation">)</span><span
                                    class="token punctuation">;</span></code></pre>
                    </li>
                </ul>
                <blockquote>
                    <p><font><font>Thymeleaf +
                        Spring集成包提供了一种</font></font><code>SpringResourceTemplateResolver</code><font><font>实现，它使用所有Spring基础架构来访问和读取应用程序中的资源，哪些是在启用Spring的应用程序中推荐的实现。</font></font>
                    </p>
                </blockquote>
                <section class="level3" id="chaining-template-resolvers">
                    <h3><font><font>链接模板解决方案</font></font></h3>
                    <p>
                        <font><font>此外，模板引擎可以指定多个模板解析器，在这种情况下，可以在它们之间建立模板解析的顺序，以便如果第一个无法解析模板，则会询问第二个模板，依此类推：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java">ClassLoaderTemplateResolver classLoaderTemplateResolver <span
                            class="token operator">=</span> <span class="token keyword">new</span> <span
                            class="token class-name">ClassLoaderTemplateResolver</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span>
classLoaderTemplateResolver<span class="token punctuation">.</span><span class="token function">setOrder</span><span
                                class="token punctuation">(</span>Integer<span class="token punctuation">.</span><span
                                class="token function">valueOf</span><span class="token punctuation">(</span><span
                                class="token number">1</span><span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
<font></font>
ServletContextTemplateResolver servletContextTemplateResolver <span class="token operator">=</span>
        <span class="token keyword">new</span> <span class="token class-name">ServletContextTemplateResolver</span><span
                                class="token punctuation">(</span>servletContext<span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
servletContextTemplateResolver<span class="token punctuation">.</span><span class="token function">setOrder</span><span
                                class="token punctuation">(</span>Integer<span class="token punctuation">.</span><span
                                class="token function">valueOf</span><span class="token punctuation">(</span><span
                                class="token number">2</span><span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
<font></font>
templateEngine<span class="token punctuation">.</span><span class="token function">addTemplateResolver</span><span
                                class="token punctuation">(</span>classLoaderTemplateResolver<span
                                class="token punctuation">)</span><span class="token punctuation">;</span>
templateEngine<span class="token punctuation">.</span><span class="token function">addTemplateResolver</span><span
                                class="token punctuation">(</span>servletContextTemplateResolver<span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    <p><font><font>当应用几个模板解析器时，建议为每个模板解析器指定模式，以便Thymeleaf可以快速丢弃那些不是要解析模板的模板解析器，从而提高性能。</font><font>这不是一个要求，而是一个建议：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java">ClassLoaderTemplateResolver classLoaderTemplateResolver <span
                            class="token operator">=</span> <span class="token keyword">new</span> <span
                            class="token class-name">ClassLoaderTemplateResolver</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span>
classLoaderTemplateResolver<span class="token punctuation">.</span><span class="token function">setOrder</span><span
                                class="token punctuation">(</span>Integer<span class="token punctuation">.</span><span
                                class="token function">valueOf</span><span class="token punctuation">(</span><span
                                class="token number">1</span><span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// This classloader will not be even asked for any templates not matching these patterns </span>
classLoaderTemplateResolver<span class="token punctuation">.</span><span
                                class="token function">getResolvablePatternSpec</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">.</span><span class="token function">addPattern</span><span
                                class="token punctuation">(</span><span
                                class="token string">"/layout/*.html"</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span>
classLoaderTemplateResolver<span class="token punctuation">.</span><span
                                class="token function">getResolvablePatternSpec</span><span
                                class="token punctuation">(</span><span class="token punctuation">)</span><span
                                class="token punctuation">.</span><span class="token function">addPattern</span><span
                                class="token punctuation">(</span><span class="token string">"/menu/*.html"</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
<font></font>
ServletContextTemplateResolver servletContextTemplateResolver <span class="token operator">=</span>
        <span class="token keyword">new</span> <span class="token class-name">ServletContextTemplateResolver</span><span
                                class="token punctuation">(</span>servletContext<span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
servletContextTemplateResolver<span class="token punctuation">.</span><span class="token function">setOrder</span><span
                                class="token punctuation">(</span>Integer<span class="token punctuation">.</span><span
                                class="token function">valueOf</span><span class="token punctuation">(</span><span
                                class="token number">2</span><span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    <p><font><font>如果</font><font>没有指定</font><font>这些可</font></font><em><font><font>解析的模式</font></font></em><font><font>，我们将依赖于</font></font><code>ITemplateResolver</code><font><font>我们使用</font><font>的每个实现的具体功能</font><font>。</font><font>请注意，并不是所有的实现都可以在解析之前确定模板的存在，因此总是可以将模板视为可</font></font><em><font><font>解析的</font></font></em><font><font>，并破坏解析链（不允许其他解析器检查相同的模板），但是不能阅读真正的资源。</font></font>
                    </p>
                    <p><font><font>所有</font></font><code>ITemplateResolver</code><font><font>附带核心Thymeleaf实现包括一种机制，将使我们能够使解析器</font></font><em><font><font>真正检查</font></font></em><font><font>如果资源考虑之前存在</font></font><em><font><font>解析</font></font></em><font><font>。</font><font>这是</font></font><code>checkExistence</code><font><font>国旗，其作用如下：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java">ClassLoaderTemplateResolver classLoaderTemplateResolver <span
                            class="token operator">=</span> <span class="token keyword">new</span> <span
                            class="token class-name">ClassLoaderTemplateResolver</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span>
classLoaderTemplateResolver<span class="token punctuation">.</span><span class="token function">setOrder</span><span
                                class="token punctuation">(</span>Integer<span class="token punctuation">.</span><span
                                class="token function">valueOf</span><span class="token punctuation">(</span><span
                                class="token number">1</span><span class="token punctuation">)</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span>
classLoaderTempalteResolver<span class="token punctuation">.</span><span class="token function">setCheckExistence</span><span
                                class="token punctuation">(</span><span class="token boolean">true</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    <p>
                        <font><font>该</font></font><code>checkExistence</code><font><font>标志强制解析器</font><font>在分辨阶段期间</font><font>执行</font><font>资源存在</font><font>的</font></font><em><font><font>真实检查</font></font></em><font><font>（并且如果存在检查返回false，则调用链中的以下解析器）。</font><font>虽然这在每种情况下可能听起来不错，但在大多数情况下，这意味着对资源本身的双重访问（一次用于检查存在，另一次用于阅读它），并且可能是某些情况下的性能问题，例如基于远程URL模板资源
                        -
                        一个潜在的性能问题，可能会通过使用模板高速缓存大大减轻（在这种情况下，模板只能</font><font>在第一次被访问时</font><font>被</font></font><em><font><font>解析</font></font></em><font><font>）。</font></font>
                    </p>
                </section>
            </section>
            <section class="level2" id="message-resolvers">
                <h2><font><font>15.2消息解析器</font></font></h2>
                <p><font><font>我们没有为我们的Grocery应用程序明确指定Message Resolver实现，如之前所解释的，这意味着正在使用的实现是一个</font></font><code>org.thymeleaf.messageresolver.StandardMessageResolver</code><font><font>对象。</font></font>
                </p>
                <p>
                    <code>StandardMessageResolver</code><font><font>是接口的标准实现</font></font><code>IMessageResolver</code><font><font>，但如果我们想要，我们可以创建自己的，适应我们应用程序的具体需求。</font></font>
                </p>
                <blockquote>
                    <p><font><font>Thymeleaf + Spring集成包默认情况下提供</font></font><code>IMessageResolver</code><font><font>使用标准Spring方式检索外部化消息的实现，通过使用</font></font><code>MessageSource</code><font><font>在Spring应用程序上下文中声明的bean。</font></font>
                    </p>
                </blockquote>
                <section class="level3" id="standard-message-resolver">
                    <h3><font><font>标准消息解析器</font></font></h3>
                    <p>
                        <font><font>那么如何</font></font><code>StandardMessageResolver</code><font><font>查找特定模板所要求的消息呢？</font></font>
                    </p>
                    <p><font><font>如果模板名称</font></font><code>home</code><font><font>位于</font></font><code>/WEB-INF/templates/home.html</code><font><font>，并且所请求的区域设置，</font></font><code>gl_ES</code><font><font>则此解析器将按以下顺序在以下文件中查找消息：</font></font>
                    </p>
                    <ul>
                        <li><code>/WEB-INF/templates/home_gl_ES.properties</code></li>
                        <li><code>/WEB-INF/templates/home_gl.properties</code></li>
                        <li><code>/WEB-INF/templates/home.properties</code></li>
                    </ul>
                    <p>
                        <font><font>有关</font></font><code>StandardMessageResolver</code><font><font>完整的消息解析机制如何工作的更多细节，</font><font>请参阅</font><font>该类</font><font>的JavaDoc文档</font><font>。</font></font>
                    </p>
                </section>
                <section class="level3" id="configuring-message-resolvers">
                    <h3><font><font>配置消息解析器</font></font></h3>
                    <p><font><font>如果我们要向模板引擎添加消息解析器（或更多），该怎么办？</font><font>简单：</font></font></p>
                    <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                     spellcheck="true">// For setting only one</span>
templateEngine<span class="token punctuation">.</span><span class="token function">setMessageResolver</span><span
                                class="token punctuation">(</span>messageResolver<span
                                class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">// For setting more than one</span>
templateEngine<span class="token punctuation">.</span><span class="token function">addMessageResolver</span><span
                                class="token punctuation">(</span>messageResolver<span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                    <p>
                        <font><font>为什么我们想要有多个消息解析器？</font><font>由于与模板解析器相同的原因：消息解析器被排序，如果第一个无法解析特定消息，则会询问第二个消息，然后是第三个等等。</font></font>
                    </p>
                </section>
            </section>
            <section class="level2" id="conversion-services">
                <h2><font><font>15.3转换服务</font></font></h2>
                <p>
                    <font><font>使我们能够通过</font><em><font>双重括号</font></em><font>语法（</font><font>）</font><font>执行数据转换和格式化操作</font><font>的</font></font><em><font><font>转换服务</font></font></em><font><font>实际上是标准方言的功能，而不是Thymeleaf模板引擎本身。</font></font><em><font></font></em><font></font><code>${{...}}</code><font></font>
                </p>
                <p>
                    <font><font>因此，配置它的方式是将接口的自定义</font></font><code>IStandardConversionService</code><font><font>实现直接</font><font>设置</font></font><code>StandardDialect</code><font><font>为正在配置到模板引擎</font><font>中的实例</font><font>。</font><font>喜欢：</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java">IStandardConversionService customConversionService <span
                        class="token operator">=</span> <span class="token punctuation">.</span><span
                        class="token punctuation">.</span><span class="token punctuation">.</span><font></font>
<font></font>
StandardDialect dialect <span class="token operator">=</span> <span class="token keyword">new</span> <span
                            class="token class-name">StandardDialect</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
dialect<span class="token punctuation">.</span><span class="token function">setConversionService</span><span
                            class="token punctuation">(</span>customConversionService<span
                            class="token punctuation">)</span><span class="token punctuation">;</span><font></font>
<font></font>
templateEngine<span class="token punctuation">.</span><span class="token function">setDialect</span><span
                            class="token punctuation">(</span>dialect<span class="token punctuation">)</span><span
                            class="token punctuation">;</span></code></pre>
                <blockquote>
                    <p>
                        <font><font>请注意，thymeleaf-spring3和thymeleaf-spring4包含</font></font><code>SpringStandardDialect</code><font><font>，并且这种方言已经预先配置了一个实现，</font></font><code>IStandardConversionService</code><font><font>将Spring自己的</font></font><em><font><font>转换服务</font></font></em><font><font>基础设施集成到了Thymeleaf。</font></font>
                    </p>
                </blockquote>
            </section>
            <section class="level2" id="logging">
                <h2><font><font>15.4记录</font></font></h2>
                <p><font><font>Thymeleaf对日志记录非常重视，并且始终通过其记录界面尝试提供最大量的有用信息。</font></font></p>
                <p><font><font>所使用的日志记录库</font></font><code>slf4j,</code><font><font>实际上充当了我们可能希望在我们的应用程序中使用的日志记录实现的桥梁（例如</font></font><code>log4j</code><font><font>）。</font></font>
                </p>
                <p>
                    <font><font>Thymeleaf班会记录</font></font><code>TRACE</code><font><font>，</font></font><code>DEBUG</code><font><font>并</font></font><code>INFO</code><font><font>-level信息，这取决于我们希望的详细程度，并且除了一般的记录它会使用与TemplateEngine类，我们可以为不同的目的而单独配置相关的三个特殊记录器：</font></font>
                </p>
                <ul>
                    <li><code>org.thymeleaf.TemplateEngine.CONFIG</code><font><font> 将在初始化期间输出库的详细配置。</font></font></li>
                    <li><code>org.thymeleaf.TemplateEngine.TIMER</code><font><font>
                        将输出有关处理每个模板所需的时间量的信息（对基准测试有用）！</font></font></li>
                    <li><code>org.thymeleaf.TemplateEngine.cache</code><font><font>是一组记录器输出有关缓存的特定信息的前缀。</font><font>尽管缓存记录器的名称可由用户配置，因此可能会更改，默认情况下它们是：
                    </font></font>
                        <ul>
                            <li><code>org.thymeleaf.TemplateEngine.cache.TEMPLATE_CACHE</code></li>
                            <li><code>org.thymeleaf.TemplateEngine.cache.EXPRESSION_CACHE</code></li>
                        </ul>
                    </li>
                </ul>
                <p><font><font>使用Thymeleaf的日志记录基础设施的示例配置</font></font><code>log4j</code><font><font>可能是：</font></font>
                </p>
                <pre><code>log4j.logger.org.thymeleaf=DEBUG<font></font>
log4j.logger.org.thymeleaf.TemplateEngine.CONFIG=TRACE<font></font>
log4j.logger.org.thymeleaf.TemplateEngine.TIMER=TRACE<font></font>
log4j.logger.org.thymeleaf.TemplateEngine.cache.TEMPLATE_CACHE=TRACE</code></pre>
            </section>
        </section>
        <section class="level1" id="template-cache">
            <h1><font><font>16模板缓存</font></font></h1>
            <p><font><font>Thymeleaf工作原理感谢一组解析器（用于标记和文本），将模板解析为事件序列（打开标签，文本，关闭标签，注释等）和一系列处理器 - 每种类型的行为需要应用 -
                修改模板解析事件序列，以便通过将原始模板与我们的数据组合来创建我们期望的结果。</font></font></p>
            <p><font><font>它还包括 - 默认情况下，存储解析模板的缓存; </font><font>在处理它们之前从读取和解析模板文件导致的事件序列。</font><font>这在Web应用程序中工作时特别有用，并且基于以下概念：</font></font>
            </p>
            <ul>
                <li><font><font>输入/输出几乎总是任何应用程序中最慢的部分。</font><font>相比之下，内存中的处理速度非常快。</font></font></li>
                <li><font><font>克隆现有的内存中事件序列总是比读取模板文件快一点，解析它并为其创建一个新的事件序列。</font></font></li>
                <li><font><font>Web应用程序通常只有几十个模板。</font></font></li>
                <li><font><font>模板文件是小到中等大小的，并且它们在应用程序运行时不被修改。</font></font></li>
            </ul>
            <p>
                <font><font>这一切都导致了在Web应用程序中缓存最常用的模板是可行的，而不浪费大量的内存，同时也可以节省大量的花费在一小组文件上的输入/输出操作的时间事实上，从来没有改变。</font></font>
            </p>
            <p><font><font>我们如何控制这个缓存？</font><font>首先，我们之前已经学到了，我们可以在模板解析器中启用或禁用它，甚至只针对特定的模板：</font></font></p>
            <pre class="  language-java"><code class="  language-java"><span class="token comment" spellcheck="true">// Default is true</span>
templateResolver<span class="token punctuation">.</span><span class="token function">setCacheable</span><span
                        class="token punctuation">(</span><span class="token boolean">false</span><span
                        class="token punctuation">)</span><span class="token punctuation">;</span>
templateResolver<span class="token punctuation">.</span><span class="token function">getCacheablePatternSpec</span><span
                        class="token punctuation">(</span><span class="token punctuation">)</span><span
                        class="token punctuation">.</span><span class="token function">addPattern</span><span
                        class="token punctuation">(</span><span class="token string">"/users/*"</span><span
                        class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
            <p><font><font>此外，我们可以通过建立我们自己的</font></font><em><font><font>Cache
                Manager</font></font></em><font><font>对象</font><font>来修改其配置</font><font>，该对象可能是默认实现的一个实例</font></font><code>StandardCacheManager</code><font><font>：</font></font>
            </p>
            <pre class="  language-java"><code class="  language-java"><span class="token comment" spellcheck="true">// Default is 50</span><span
                    id="pos_placeholder"
                    style="width: 0px; height: 0px; visibility: hidden; margin: 0px; padding: 0px;"></span>
StandardCacheManager cacheManager <span class="token operator">=</span> <span class="token keyword">new</span> <span
                        class="token class-name">StandardCacheManager</span><span
                        class="token punctuation">(</span><span class="token punctuation">)</span><span
                        class="token punctuation">;</span>
cacheManager<span class="token punctuation">.</span><span class="token function">setTemplateCacheMaxSize</span><span
                        class="token punctuation">(</span><span class="token number">100</span><span
                        class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
templateEngine<span class="token punctuation">.</span><span class="token function">setCacheManager</span><span
                        class="token punctuation">(</span>cacheManager<span class="token punctuation">)</span><span
                        class="token punctuation">;</span></code></pre>
            <p>
                <font><font>有关</font></font><code>org.thymeleaf.cache.StandardCacheManager</code><font><font>配置缓存的更多信息，</font><font>请参阅javadoc
                API </font><font>。</font></font></p>
            <p><font><font>可以从模板缓存中手动删除条目：</font></font></p>
            <pre class="  language-java"><code class="  language-java"><span class="token comment" spellcheck="true">// Clear the cache completely</span>
templateEngine<span class="token punctuation">.</span><span class="token function">clearTemplateCache</span><span
                        class="token punctuation">(</span><span class="token punctuation">)</span><span
                        class="token punctuation">;</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">// Clear a specific template from the cache</span>
templateEngine<span class="token punctuation">.</span><span class="token function">clearTemplateCacheFor</span><span
                        class="token punctuation">(</span><span class="token string">"/users/userList"</span><span
                        class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
        </section>
        <section class="level1" id="decoupled-template-logic">
            <h1><font><font>17去耦模板逻辑</font></font></h1>
            <section class="level2" id="decoupled-logic-the-concept">
                <h2><font><font>17.1解耦逻辑：概念</font></font></h2>
                <p>
                    <font><font>到目前为止，我们已经为我们的杂货店工作了，</font></font><em><font><font>通常</font></font></em><font><font>使用模板</font><font>，以逻辑的形式插入到我们的模板中。</font></font>
                </p>
                <p><font><font>但Thymeleaf也让我们彻底</font></font><em><font><font>脱钩</font></font></em><font><font>从逻辑模板标记，允许创建</font></font><strong><font><font>完全逻辑较少标记模板</font></font></strong><font><font>在</font></font><code>HTML</code><font><font>和</font></font><code>XML</code><font><font>模板模式。</font></font>
                </p>
                <p>
                    <font><font>主要思想是模板逻辑将在一个单独的</font></font><em><font><font>逻辑文件中</font></font></em><font><font>定义</font><font>（更准确的</font></font><em><font><font>逻辑资源</font></font></em><font><font>，因为它不需要是一个</font></font><em><font><font>文件</font></font></em><font><font>）。</font><font>默认情况下，该逻辑资源将是与模板文件居住在同一位置（例如文件夹）的附加文件，具有相同的名称但具有</font></font><code>.th.xml</code><font><font>扩展</font><font>名</font><font>：</font></font>
                </p>
                <pre><code>/templates<font></font>
+-&gt;/home.html<font></font>
+-&gt;/home.th.xml</code></pre>
                <p>
                    <font><font>所以</font></font><code>home.html</code><font><font>文件可以是完全无逻辑的。</font><font>它可能看起来像这样：</font></font>
                </p>
                <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span
        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span> <span
            class="token attr-name">id</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>usersTable<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>username<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Jeremy Grapefruit<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>usertype<span
                class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>Normal User<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>username<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Alice Watermelon<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>usertype<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Administrator<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p><font><font>绝对没有thymeleaf代码。</font><font>这是一个没有Thymeleaf或模板知识的设计师可以创建，编辑和/或理解的模板文件。</font><font>或者由一些外部系统提供的HTML片段，没有Thymeleaf钩子。</font></font>
                </p>
                <p><font><font>现在，</font></font><code>home.html</code><font><font>通过创建我们的附加</font></font><code>home.th.xml</code><font><font>文件</font><font>，将该</font><font>模板转换为Thymeleaf模板</font><font>：</font></font>
                </p>
                <pre class="  language-xml"><code class="  language-xml"><span class="token prolog">&lt;?xml version="1.0"?&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>thlogic</span><span
        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>attr</span> <span
          class="token attr-name">sel</span><span class="token attr-value"><span class="token punctuation">=</span><span
          class="token punctuation">"</span>#usersTable<span class="token punctuation">"</span></span> <span
          class="token attr-name"><span class="token namespace">th:</span>remove</span><span
          class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>all-but-first<span
          class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>attr</span> <span
            class="token attr-name">sel</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>/tr[0]<span
            class="token punctuation">"</span></span> <span class="token attr-name"><span
            class="token namespace">th:</span>each</span><span class="token attr-value"><span class="token punctuation">=</span><span
            class="token punctuation">"</span>user : ${users}<span class="token punctuation">"</span></span><span
            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>attr</span> <span
              class="token attr-name">sel</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>td.username<span
              class="token punctuation">"</span></span> <span class="token attr-name"><span
              class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>${user.name}<span
              class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>attr</span> <span
              class="token attr-name">sel</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>td.usertype<span
              class="token punctuation">"</span></span> <span class="token attr-name"><span
              class="token namespace">th:</span>text</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>#{|user.type.${user.type}|}<span
              class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>attr</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>attr</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>thlogic</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>在这里我们可以看到</font></font><code>&lt;attr&gt;</code><font><font>一个</font></font><code>thlogic</code><font><font>块中</font><font>的很多</font><font>标签</font><font>。</font><font>这些</font></font><code>&lt;attr&gt;</code><font><font>标签</font><font>通过其</font><font>属性</font><font>选择的原始模板的节点</font><font>执行</font></font><em><font><font>属性注入</font></font></em><font></font><code>sel</code><font><font>，其中包含Thymeleaf </font></font><em><font><font>标记选择器</font></font></em><font><font>（实际为</font></font><em><font><font>AttoParser标记选择器</font></font></em><font><font>）。</font></font>
                </p>
                <p><font><font>还要注意，</font></font><code>&lt;attr&gt;</code><font><font>标签可以嵌套，以便</font></font><em><font><font>附加</font></font></em><font><font>它们的选择器</font><font>。</font><font>即</font></font><code>sel="/tr[0]"</code><font><font>上述中，例如，将被处理为</font></font><code>sel="#usersTable/tr[0]"</code><font><font>。</font><font>而用户名的选择器</font></font><code>&lt;td&gt;</code><font><font>将被处理为</font></font><code>sel="#usersTable/tr[0]//td.username"</code><font><font>。</font></font>
                </p>
                <p><font><font>所以一旦合并，上面看到的两个文件将是一样的：</font></font></p>
                <pre class="  language-html"><code class="  language-html"><span class="token doctype">&lt;!DOCTYPE html&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span
        class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span
          class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span> <span
            class="token attr-name">id</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>usersTable<span
            class="token punctuation">"</span></span> <span class="token attr-name"><span
            class="token namespace">th:</span>remove</span><span class="token attr-value"><span
            class="token punctuation">=</span><span class="token punctuation">"</span>all-but-first<span
            class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span> <span
              class="token attr-name"><span class="token namespace">th:</span>each</span><span class="token attr-value"><span
              class="token punctuation">=</span><span class="token punctuation">"</span>user : ${users}<span
              class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>username<span
                class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>${user.name}<span class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>Jeremy Grapefruit<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>usertype<span
                class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">th:</span>text</span><span
                class="token attr-value"><span class="token punctuation">=</span><span
                class="token punctuation">"</span>#{|user.type.${user.type}|}<span
                class="token punctuation">"</span></span><span
                class="token punctuation">&gt;</span></span>Normal User<span class="token tag"><span
                            class="token tag"><span class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span
              class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>username<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Alice Watermelon<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span
                class="token attr-name">class</span><span class="token attr-value"><span
                class="token punctuation">=</span><span class="token punctuation">"</span>usertype<span
                class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Administrator<span
                            class="token tag"><span class="token tag"><span
                            class="token punctuation">&lt;/</span>td</span><span
                            class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span
              class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span
            class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span
          class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span
        class="token punctuation">&gt;</span></span></code></pre>
                <p>
                    <font><font>这看起来比较熟悉，并且</font><font>比创建两个单独的文件</font><font>确实不那么</font></font><em><font><font>冗长</font></font></em><font><font>。</font><font>但是解耦</font></font><em><font><font>模板的优点</font></font></em><font><font>是，我们可以给我们的模板完全独立于Thymeleaf，因此从设计的角度来看更好的可维护性。</font></font>
                </p>
                <p><font><font>当然</font><font>，仍然需要设计师或开发</font></font><em><font><font>人员</font></font></em><font><font>之间的</font><font>一些</font><em><font>合同</font></em><font>
                    - 例如用户</font></font><code>&lt;table&gt;</code><font><font>需要这样</font><font>的事实</font></font><code>id="usersTable"</code><font><font>，但在许多情况下，纯HTML模板将是设计和开发团队之间更好的沟通工具。</font></font>
                </p>
            </section>
            <section class="level2" id="configuring-decoupled-templates">
                <h2><font><font>17.2配置去耦模板</font></font></h2>
                <section class="level3" id="enabling-decoupled-templates">
                    <h3><font><font>启用解耦模板</font></font></h3>
                    <p>
                        <font><font>默认情况下，每个模板不会期望解耦逻辑。</font><font>相反，配置的模板解析器（实现</font></font><code>ITemplateResolver</code><font><font>）将需要将</font><font>其解析的模板特别</font><font>标记为</font></font><em><font><font>使用解耦逻辑</font></font></em><font><font>。</font></font>
                    </p>
                    <p><font><font>除了</font></font><code>StringTemplateResolver</code><font><font>（不允许解耦逻辑）之外，所有其他开箱即用的实现</font></font><code>ITemplateResolver</code><font><font>将提供一个标记</font></font><code>useDecoupledLogic</code><font><font>，将标记由该解析器解析的所有模板，以将其全部或部分逻辑生活在单独的资源中：</font></font>
                    </p>
                    <pre class="  language-java"><code class="  language-java"><span class="token keyword">final</span> ServletContextTemplateResolver templateResolver <span
                            class="token operator">=</span>
        <span class="token keyword">new</span> <span class="token class-name">ServletContextTemplateResolver</span><span
                                class="token punctuation">(</span>servletContext<span class="token punctuation">)</span><span
                                class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
templateResolver<span class="token punctuation">.</span><span class="token function">setUseDecoupledLogic</span><span
                                class="token punctuation">(</span><span class="token boolean">true</span><span
                                class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
                </section>
                <section class="level3" id="mixing-coupled-and-decoupled-logic">
                    <h3><font><font>混合耦合和去耦逻辑</font></font></h3>
                    <p>
                        <font><font>解耦模板逻辑，如果启用，不是一个要求。</font><font>启用时，这意味着引擎将</font></font><em><font><font>查找</font></font></em><font><font>包含解耦逻辑的资源，解析并将其与原始模板合并（如果存在）。</font><font>如果解耦逻辑资源不存在，则不会抛出任何错误。</font></font>
                    </p>
                    <p>
                        <font><font>另外，在同一个模板中，我们可以混合</font></font><em><font><font>耦合</font></font></em><font><font>和</font></font><em><font><font>去耦</font></font></em><font><font>逻辑，例如通过在原始模板文件中添加一些Thymeleaf属性，而将其他逻辑文件留给另外的解耦逻辑文件。</font><font>最常见的情况是使用新的（在v3.0）</font></font><code>th:ref</code><font><font>属性。</font></font>
                    </p>
                </section>
            </section>
            <section class="level2" id="the-thref-attribute">
                <h2><font><font>17.3 th：ref属性</font></font></h2>
                <p><code>th:ref</code><font><font>只是一个标记属性。</font><font>从处理的角度来看，它什么也不做，当模板被处理时就会消失，但是它的用处在于它作为一个</font></font><em><font><font>标记引用</font></font></em><font><font>，即可以通过</font></font><em><font><font>标记选择器</font></font></em><font><font>的名称来解析，</font><font>就像</font></font><em><font><font>标签名称</font></font></em><font><font>或</font></font><em><font><font>片段一样</font></font></em><font><font>（</font></font><code>th:fragment</code><font><font>）。</font></font>
                </p>
                <p><font><font>所以如果我们有一个选择器：</font></font></p>
                <pre class="  language-xml"><code class="  language-xml">  <span class="token tag"><span
                        class="token tag"><span class="token punctuation">&lt;</span>attr</span> <span
                        class="token attr-name">sel</span><span class="token attr-value"><span
                        class="token punctuation">=</span><span class="token punctuation">"</span>whatever<span
                        class="token punctuation">"</span></span> <span class="token attr-name">...</span><span
                        class="token punctuation">/&gt;</span></span></code></pre>
                <p><font><font>这将匹配：</font></font></p>
                <ul>
                    <li><font><font>任何</font></font><code>&lt;whatever&gt;</code><font><font>标签。</font></font></li>
                    <li>
                        <font><font>任何带有</font></font><code>th:fragment="whatever"</code><font><font>属性的</font><font>标签</font><font>。</font></font>
                    </li>
                    <li>
                        <font><font>任何带有</font></font><code>th:ref="whatever"</code><font><font>属性的</font><font>标签</font><font>。</font></font>
                    </li>
                </ul>
                <p>
                    <font><font>什么是优势</font></font><code>th:ref</code><font><font>对抗，例如，使用纯HTML </font></font><code>id</code><font><font>属性？</font><font>仅仅是事实，我们可能不希望添加这么多</font></font><code>id</code><font><font>和</font></font><code>class</code><font><font>属性，我们的标记作为</font></font><em><font><font>逻辑锚</font></font></em><font><font>，这最终可能会</font></font><em><font><font>污染</font></font></em><font><font>我们的产量。</font></font>
                </p>
                <p><font><font>在同样的意义上，什么是缺点</font></font><code>th:ref</code><font><font>？</font><font>那么很明显，我们会在我们的模板中添加一些Thymeleaf逻辑（</font></font><em><font><font>“逻辑”</font></font></em><font><font>）。</font></font>
                </p>
                <p>
                    <font><font>请注意，该属性的</font></font><code>th:ref</code><font><font>适用性</font></font><strong><font><font>不仅适用于解耦逻辑模板文件</font></font></strong><font><font>：它在其他类型的场景中也是一样的，如片段表达式（</font></font><code>~{...}</code><font><font>）。</font></font>
                </p>
            </section>
            <section class="level2" id="performance-impact-of-decoupled-templates">
                <h2><font><font>17.4去耦模板的性能影响</font></font></h2>
                <p><font><font>影响极小。</font><font>当解析的模板被标记为使用解耦逻辑并且不被缓存时，模板逻辑资源将被首先解析，并被解析并处理成内存中的一系列指令：基本上是要注入到每个标记选择器的属性列表。</font></font>
                </p>
                <p><font><font>但是，这是唯一的</font></font><em><font><font>额外步骤</font></font></em><font><font>需要的，因为，在这之后，真正的模板将被解析，同时解析这些属性将被注入</font></font><em><font><font>上即时</font></font></em><font><font>解析器本身，得益于先进的功能，在AttoParser节点选择。</font><font>所以解析的节点将从解析器中出来，就好像他们注入的属性写在原始模板文件中一样。</font></font>
                </p>
                <p><font><font>这个最大的优点 </font><font>当模板被配置为缓存时，它将被缓存已经包含注入的属性。</font><font>因此，对可</font></font><em><font><font>缓存模板</font></font></em><font><font>使用</font><em><font>解耦模板</font></em><font>的开销</font><font>，一旦被缓存，将绝对</font></font><em><font><font>为零</font></font></em><font><font>。</font></font>
                </p>
            </section>
            <section class="level2" id="resolution-of-decoupled-logic">
                <h2><font><font>17.5解耦逻辑的分辨率</font></font></h2>
                <p><font><font>Thymeleaf解决与每个模板相对应的解耦逻辑资源的方式可由用户配置。</font><font>由扩展点确定</font></font><code>org.thymeleaf.templateparser.markup.decoupled.IDecoupledTemplateLogicResolver</code><font><font>，为其提供</font></font><em><font><font>默认实现</font></font></em><font><font>：</font></font><code>StandardDecoupledTemplateLogicResolver</code><font><font>。</font></font>
                </p>
                <p><font><font>这个标准实现是做什么的？</font></font></p>
                <ul>
                    <li><font><font>首先，它将a </font></font><code>prefix</code><font><font>和a </font><font>应用于</font><font>模板资源</font></font><code>suffix</code><font><font>的</font></font><em><font><font>基本名称</font></font></em><font><font>（通过其</font></font><code>ITemplateResource#getBaseName()</code><font><font>方法获得）。</font><font>可以配置前缀和后缀，默认情况下，前缀将为空，后缀为</font></font><code>.th.xml</code><font><font>。</font></font>
                    </li>
                    <li>
                        <font><font>其次，它要求模板资源</font><font>通过其</font><font>方法</font><font>解析具有</font><font>计算名称</font><font>的</font></font><em><font><font>相对资源</font></font></em><font></font><code>ITemplateResource#relative(String
                        relativeLocation)</code><font><font>。</font></font></li>
                </ul>
                <p>
                    <font></font><code>IDecoupledTemplateLogicResolver</code><font><font>要使用</font><font>的具体实现</font><font>可以</font></font><code>TemplateEngine</code><font><font>轻松配置：</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java"><span class="token keyword">final</span> StandardDecoupledTemplateLogicResolver decoupledresolver <span
                        class="token operator">=</span>
        <span class="token keyword">new</span> <span
                            class="token class-name">StandardDecoupledTemplateLogicResolver</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">;</span>
decoupledResolver<span class="token punctuation">.</span><span class="token function">setPrefix</span><span
                            class="token punctuation">(</span><span class="token string">"../viewlogic/"</span><span
                            class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
templateEngine<span class="token punctuation">.</span><span
                            class="token function">setDecoupledTemplateLogicResolver</span><span
                            class="token punctuation">(</span>decoupledResolver<span
                            class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
            </section>
        </section>
        <section class="level1" id="appendix-a-expression-basic-objects">
            <h1><font><font>18附录A：表达式基本对象</font></font></h1>
            <p><font><font>一些对象和变量映射始终可以被调用。</font><font>我们来看看他们：</font></font></p>
            <section class="level3" id="base-objects">
                <h3><font><font>基础对象</font></font></h3>
                <ul>
                    <li>
                        <strong><font><font>#ctx</font></font></strong><font><font>：上下文对象。</font><font>实施</font></font><code>org.thymeleaf.context.IContext</code><font><font>或</font></font><code>org.thymeleaf.context.IWebContext</code><font><font>取决于我们的环境（独立或网络）。</font></font>
                    </li>
                </ul>
                <p>
                    <font><font>注意</font></font><code>#vars</code><font><font>并且</font></font><code>#root</code><font><font>是同一对象的</font></font><code>#ctx</code><font><font>synomyns </font><font>，但建议使用</font><font>。</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.context.IContext
 * ======================================================================
 */</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#ctx<span class="token punctuation">.</span>locale<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#ctx<span class="token punctuation">.</span>variableNames<span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.context.IWebContext
 * ======================================================================
 */</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#ctx<span class="token punctuation">.</span>request<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#ctx<span class="token punctuation">.</span>response<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#ctx<span class="token punctuation">.</span>session<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#ctx<span class="token punctuation">.</span>servletContext<span
                            class="token punctuation">}</span></code></pre>
                <ul>
                    <li><strong><font><font>#locale</font></font></strong><font><font>：直接访问</font></font><code>java.util.Locale</code><font><font>当前请求</font><font>的</font><font>关联。</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java">$<span class="token punctuation">{</span>#locale<span
                        class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="web-context-namespaces-for-requestsession-attributes-etc.">
                <h3><font><font>用于请求/会话属性等的Web上下文名称空间</font></font></h3>
                <p><font><font>在Web环境中使用Thymeleaf时，我们可以使用一系列快捷方式来访问请求参数，会话属性和应用程序属性：</font></font></p>
                <blockquote>
                    <p><font><font>注意这些不是</font></font><em><font><font>上下文对象</font></font></em><font><font>，而是添加到上下文中的映射作为变量，所以我们无需访问它们</font></font><code>#</code><font><font>。</font><font>在某种程度上，它们作为</font></font><em><font><font>命名空间</font></font></em><font><font>。</font></font>
                    </p>
                </blockquote>
                <ul>
                    <li><strong><font><font>param</font></font></strong><font><font>：用于检索请求参数。</font></font><code>${param.foo}</code><font><font>是一个</font><font>请求参数</font></font><code>String[]</code><font><font>的值</font></font><code>foo</code><font><font>，所以</font></font><code>${param.foo[0]}</code><font><font>通常用于获取第一个值。</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ============================================================================
 * See javadoc API for class org.thymeleaf.context.WebRequestParamsVariablesMap
 * ============================================================================
 */</span><font></font>
<font></font>
$<span class="token punctuation">{</span>param<span class="token punctuation">.</span>foo<span
                            class="token punctuation">}</span>              <span class="token comment"
                                                                                  spellcheck="true">// Retrieves a String[] with the values of request parameter 'foo'</span>
$<span class="token punctuation">{</span>param<span class="token punctuation">.</span><span
                            class="token function">size</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>param<span class="token punctuation">.</span><span class="token function">isEmpty</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>param<span class="token punctuation">.</span><span class="token function">containsKey</span><span
                            class="token punctuation">(</span><span class="token string">'foo'</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
                <ul>
                    <li><strong><font><font>会话</font></font></strong><font><font>：用于检索会话属性。</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.context.WebSessionVariablesMap
 * ======================================================================
 */</span><font></font>
<font></font>
$<span class="token punctuation">{</span>session<span class="token punctuation">.</span>foo<span
                            class="token punctuation">}</span>                 <span class="token comment"
                                                                                     spellcheck="true">// Retrieves the session atttribute 'foo'</span>
$<span class="token punctuation">{</span>session<span class="token punctuation">.</span><span class="token function">size</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>session<span class="token punctuation">.</span><span class="token function">isEmpty</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>session<span class="token punctuation">.</span><span class="token function">containsKey</span><span
                            class="token punctuation">(</span><span class="token string">'foo'</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
                <ul>
                    <li><strong><font><font>应用程序</font></font></strong><font><font>：用于检索应用程序/
                        servlet上下文属性。</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * =============================================================================
 * See javadoc API for class org.thymeleaf.context.WebServletContextVariablesMap
 * =============================================================================
 */</span><font></font>
<font></font>
$<span class="token punctuation">{</span>application<span class="token punctuation">.</span>foo<span
                            class="token punctuation">}</span>              <span class="token comment"
                                                                                  spellcheck="true">// Retrieves the ServletContext atttribute 'foo'</span>
$<span class="token punctuation">{</span>application<span class="token punctuation">.</span><span
                            class="token function">size</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>application<span class="token punctuation">.</span><span
                            class="token function">isEmpty</span><span class="token punctuation">(</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>application<span class="token punctuation">.</span><span
                            class="token function">containsKey</span><span class="token punctuation">(</span><span
                            class="token string">'foo'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
                <p>
                    <font><font>请注意，</font></font><strong><font><font>无需为访问请求属性</font></font></strong><font><font>（而不是</font></font><em><font><font>请求参数</font></font></em><font><font>）</font><strong><font>指定命名空间，</font></strong><font>因为所有请求属性将自动添加到上下文中作为上下文根中的变量：</font></font>
                </p>
                <pre class="  language-java"><code class="  language-java">$<span class="token punctuation">{</span>myRequestAttribute<span
                        class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="web-context-objects">
                <h3><font><font>Web上下文对象</font></font></h3>
                <p><font><font>在Web环境中，还可以直接访问以下对象（请注意，这些对象不是映射/命名空间）：</font></font></p>
                <ul>
                    <li><strong><font><font>#request</font></font></strong><font><font>：直接访问</font></font><code>javax.servlet.http.HttpServletRequest</code><font><font>与当前请求相关联</font><font>的</font><font>对象。</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java">$<span class="token punctuation">{</span>#request<span
                        class="token punctuation">.</span><span class="token function">getAttribute</span><span
                        class="token punctuation">(</span><span class="token string">'foo'</span><span
                        class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#request<span class="token punctuation">.</span><span class="token function">getParameter</span><span
                            class="token punctuation">(</span><span class="token string">'foo'</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#request<span class="token punctuation">.</span><span class="token function">getContextPath</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#request<span class="token punctuation">.</span><span class="token function">getRequestName</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
                <ul>
                    <li><strong><font><font>#session</font></font></strong><font><font>：直接访问</font></font><code>javax.servlet.http.HttpSession</code><font><font>与当前请求相关联</font><font>的</font><font>对象。</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java">$<span class="token punctuation">{</span>#session<span
                        class="token punctuation">.</span><span class="token function">getAttribute</span><span
                        class="token punctuation">(</span><span class="token string">'foo'</span><span
                        class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#session<span class="token punctuation">.</span>id<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#session<span class="token punctuation">.</span>lastAccessedTime<span
                            class="token punctuation">}</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
                <ul>
                    <li><strong><font><font>#servletContext</font></font></strong><font><font>：直接访问</font></font><code>javax.servlet.ServletContext</code><font><font>与当前请求相关联</font><font>的</font><font>对象。</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java">$<span class="token punctuation">{</span>#servletContext<span
                        class="token punctuation">.</span><span class="token function">getAttribute</span><span
                        class="token punctuation">(</span><span class="token string">'foo'</span><span
                        class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#servletContext<span class="token punctuation">.</span>contextPath<span
                            class="token punctuation">}</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
            </section>
        </section>
        <section class="level1" id="appendix-b-expression-utility-objects">
            <h1><font><font>19附录B：表达式实用程序对象</font></font></h1>
            <section class="level3" id="execution-info">
                <h3><font><font>执行信息</font></font></h3>
                <ul>
                    <li><strong><font><font>#execInfo</font></font></strong><font><font>：表达式对象，提供有关在Thymeleaf标准表达式内正在处理的模板的有用信息。</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.ExecutionInfo
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Return the name and mode of the 'leaf' template. This means the template
 * from where the events being processed were parsed. So if this piece of
 * code is not in the root template "A" but on a fragment being inserted
 * into "A" from another template called "B", this will return "B" as a
 * name, and B's mode as template mode.
 */</span>
$<span class="token punctuation">{</span>#execInfo<span class="token punctuation">.</span>templateName<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#execInfo<span class="token punctuation">.</span>templateMode<span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Return the name and mode of the 'root' template. This means the template
 * that the template engine was originally asked to process. So if this
 * piece of code is not in the root template "A" but on a fragment being
 * inserted into "A" from another template called "B", this will still
 * return "A" and A's template mode.
 */</span>
$<span class="token punctuation">{</span>#execInfo<span class="token punctuation">.</span>processedTemplateName<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#execInfo<span class="token punctuation">.</span>processedTemplateMode<span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Return the stacks (actually, List&lt;String&gt; or List&lt;TemplateMode&gt;) of
 * templates being processed. The first element will be the
 * 'processedTemplate' (the root one), the last one will be the 'leaf'
 * template, and in the middle all the fragments inserted in nested
 * manner to reach the leaf from the root will appear.
 */</span>
$<span class="token punctuation">{</span>#execInfo<span class="token punctuation">.</span>templateNames<span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#execInfo<span class="token punctuation">.</span>templateModes<span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Return the stack of templates being processed similarly (and in the
 * same order) to 'templateNames' and 'templateModes', but returning
 * a List&lt;TemplateData&gt; with the full template metadata.
 */</span>
$<span class="token punctuation">{</span>#execInfo<span class="token punctuation">.</span>templateStack<span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="messages-1">
                <h3><font><font>消息</font></font></h3>
                <ul>
                    <li>
                        <strong><font><font>#messages</font></font></strong><font><font>：用于在变量表达式中获取外部化消息的实用方法，与使用</font></font><code>#{...}</code><font><font>语法</font><font>获得的方式相同</font><font>。</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Messages
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Obtain externalized messages. Can receive a single key, a key plus arguments,
 * or an array/list/set of keys (in which case it will return an array/list/set of
 * externalized messages).
 * If a message is not found, a default message (like '??msgKey??') is returned.
 */</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msg</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msg</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">,</span> param1<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msg</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">,</span> param1<span
                            class="token punctuation">,</span> param2<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msg</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">,</span> param1<span
                            class="token punctuation">,</span> param2<span
                            class="token punctuation">,</span> param3<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msgWithParams</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">,</span> <span class="token keyword">new</span> <span
                            class="token class-name">Object</span><span class="token punctuation">[</span><span
                            class="token punctuation">]</span> <span class="token punctuation">{</span>param1<span
                            class="token punctuation">,</span> param2<span
                            class="token punctuation">,</span> param3<span
                            class="token punctuation">,</span> param4<span class="token punctuation">}</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">arrayMsg</span><span
                            class="token punctuation">(</span>messageKeyArray<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">listMsg</span><span
                            class="token punctuation">(</span>messageKeyList<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">setMsg</span><span
                            class="token punctuation">(</span>messageKeySet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Obtain externalized messages or null. Null is returned instead of a default
 * message if a message for the specified key is not found.
 */</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msgOrNull</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msgOrNull</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">,</span> param1<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msgOrNull</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">,</span> param1<span
                            class="token punctuation">,</span> param2<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msgOrNull</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">,</span> param1<span
                            class="token punctuation">,</span> param2<span
                            class="token punctuation">,</span> param3<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">msgOrNullWithParams</span><span
                            class="token punctuation">(</span><span class="token string">'msgKey'</span><span
                            class="token punctuation">,</span> <span class="token keyword">new</span> <span
                            class="token class-name">Object</span><span class="token punctuation">[</span><span
                            class="token punctuation">]</span> <span class="token punctuation">{</span>param1<span
                            class="token punctuation">,</span> param2<span
                            class="token punctuation">,</span> param3<span
                            class="token punctuation">,</span> param4<span class="token punctuation">}</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">arrayMsgOrNull</span><span
                            class="token punctuation">(</span>messageKeyArray<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">listMsgOrNull</span><span
                            class="token punctuation">(</span>messageKeyList<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#messages<span class="token punctuation">.</span><span class="token function">setMsgOrNull</span><span
                            class="token punctuation">(</span>messageKeySet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="urisurls">
                <h3><font><font>URI / URL</font></font></h3>
                <ul>
                    <li><strong><font><font>#uris</font></font></strong><font><font>：用于在Thymeleaf标准表达式中执行URI /
                        URL操作（尤其是转义/取消转义）的实用程序对象。</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Uris
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Escape/Unescape as a URI/URL path
 */</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">escapePath</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">escapePath</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">,</span> encoding<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">unescapePath</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">unescapePath</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">,</span> encoding<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Escape/Unescape as a URI/URL path segment (between '/' symbols)
 */</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">escapePathSegment</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">escapePathSegment</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">,</span> encoding<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">unescapePathSegment</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">unescapePathSegment</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">,</span> encoding<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Escape/Unescape as a Fragment Identifier (#frag)
 */</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">escapeFragmentId</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">escapeFragmentId</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">,</span> encoding<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">unescapeFragmentId</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">unescapeFragmentId</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">,</span> encoding<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Escape/Unescape as a Query Parameter (?var=value)
 */</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">escapeQueryParam</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">escapeQueryParam</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">,</span> encoding<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">unescapeQueryParam</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#uris<span class="token punctuation">.</span><span class="token function">unescapeQueryParam</span><span
                            class="token punctuation">(</span>uri<span class="token punctuation">,</span> encoding<span
                            class="token punctuation">)</span><span class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="conversions">
                <h3><font><font>转换</font></font></h3>
                <ul>
                    <li>
                        <strong><font><font>#conversions</font></font></strong><font><font>：允许在</font><font>模板的任意位置</font><font>执行</font></font><em><font><font>转换服务的</font></font></em><font><font>实用程序对象</font><font>：</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Conversions
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Execute the desired conversion of the 'object' value into the
 * specified class.
 */</span>
$<span class="token punctuation">{</span>#conversions<span class="token punctuation">.</span><span
                            class="token function">convert</span><span class="token punctuation">(</span>object<span
                            class="token punctuation">,</span> <span
                            class="token string">'java.util.TimeZone'</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#conversions<span class="token punctuation">.</span><span
                            class="token function">convert</span><span class="token punctuation">(</span>object<span
                            class="token punctuation">,</span> targetClass<span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="dates">
                <h3><font><font>日期</font></font></h3>
                <ul>
                    <li>
                        <strong><font><font>#dates</font></font></strong><font><font>：</font></font><code>java.util.Date</code><font><font>对象的</font><font>实用程序方法</font><font>：</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Dates
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Format date with the standard locale format
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">format</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">arrayFormat</span><span
                            class="token punctuation">(</span>datesArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">listFormat</span><span
                            class="token punctuation">(</span>datesList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">setFormat</span><span
                            class="token punctuation">(</span>datesSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Format date with the ISO8601 format
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">formatISO</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">arrayFormatISO</span><span
                            class="token punctuation">(</span>datesArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">listFormatISO</span><span
                            class="token punctuation">(</span>datesList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">setFormatISO</span><span
                            class="token punctuation">(</span>datesSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Format date with the specified pattern
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">format</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">,</span> <span
                            class="token string">'dd/MMM/yyyy HH:mm'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">arrayFormat</span><span
                            class="token punctuation">(</span>datesArray<span class="token punctuation">,</span> <span
                            class="token string">'dd/MMM/yyyy HH:mm'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">listFormat</span><span
                            class="token punctuation">(</span>datesList<span class="token punctuation">,</span> <span
                            class="token string">'dd/MMM/yyyy HH:mm'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">setFormat</span><span
                            class="token punctuation">(</span>datesSet<span class="token punctuation">,</span> <span
                            class="token string">'dd/MMM/yyyy HH:mm'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Obtain date properties
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span
                            class="token function">day</span><span class="token punctuation">(</span>date<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>                    <span
                            class="token comment" spellcheck="true">// also arrayDay(...), listDay(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">month</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                  <span class="token comment"
                                                                                      spellcheck="true">// also arrayMonth(...), listMonth(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">monthName</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>              <span class="token comment"
                                                                                  spellcheck="true">// also arrayMonthName(...), listMonthName(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">monthNameShort</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>         <span class="token comment" spellcheck="true">// also arrayMonthNameShort(...), listMonthNameShort(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span
                            class="token function">year</span><span class="token punctuation">(</span>date<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>                   <span
                            class="token comment" spellcheck="true">// also arrayYear(...), listYear(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">dayOfWeek</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>              <span class="token comment"
                                                                                  spellcheck="true">// also arrayDayOfWeek(...), listDayOfWeek(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">dayOfWeekName</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>          <span class="token comment" spellcheck="true">// also arrayDayOfWeekName(...), listDayOfWeekName(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">dayOfWeekNameShort</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>     <span class="token comment" spellcheck="true">// also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span
                            class="token function">hour</span><span class="token punctuation">(</span>date<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>                   <span
                            class="token comment" spellcheck="true">// also arrayHour(...), listHour(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">minute</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                 <span class="token comment"
                                                                                     spellcheck="true">// also arrayMinute(...), listMinute(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">second</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                 <span class="token comment"
                                                                                     spellcheck="true">// also arraySecond(...), listSecond(...), etc.</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">millisecond</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>            <span class="token comment" spellcheck="true">// also arrayMillisecond(...), listMillisecond(...), etc.</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Create date (java.util.Date) objects from its components
 */</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">create</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">create</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">create</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span class="token punctuation">,</span>second<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">create</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span class="token punctuation">,</span>second<span
                            class="token punctuation">,</span>millisecond<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Create a date (java.util.Date) object for the current date and time
 */</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">createNow</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">createNowForTimeZone</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Create a date (java.util.Date) object for the current date (time set to 00:00)
 */</span>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">createToday</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#dates<span class="token punctuation">.</span><span class="token function">createTodayForTimeZone</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="calendars">
                <h3><font><font>日历</font></font></h3>
                <ul>
                    <li>
                        <strong><font><font>#calendars</font></font></strong><font><font>：类似</font></font><code>#dates</code><font><font>，但</font></font><code>java.util.Calendar</code><font><font>对象：</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Calendars
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Format calendar with the standard locale format
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">format</span><span
                            class="token punctuation">(</span>cal<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">arrayFormat</span><span
                            class="token punctuation">(</span>calArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">listFormat</span><span
                            class="token punctuation">(</span>calList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">setFormat</span><span
                            class="token punctuation">(</span>calSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Format calendar with the ISO8601 format
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">formatISO</span><span
                            class="token punctuation">(</span>cal<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">arrayFormatISO</span><span
                            class="token punctuation">(</span>calArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">listFormatISO</span><span
                            class="token punctuation">(</span>calList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">setFormatISO</span><span
                            class="token punctuation">(</span>calSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Format calendar with the specified pattern
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">format</span><span
                            class="token punctuation">(</span>cal<span class="token punctuation">,</span> <span
                            class="token string">'dd/MMM/yyyy HH:mm'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">arrayFormat</span><span
                            class="token punctuation">(</span>calArray<span class="token punctuation">,</span> <span
                            class="token string">'dd/MMM/yyyy HH:mm'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">listFormat</span><span
                            class="token punctuation">(</span>calList<span class="token punctuation">,</span> <span
                            class="token string">'dd/MMM/yyyy HH:mm'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">setFormat</span><span
                            class="token punctuation">(</span>calSet<span class="token punctuation">,</span> <span
                            class="token string">'dd/MMM/yyyy HH:mm'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Obtain calendar properties
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">day</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                <span class="token comment"
                                                                                    spellcheck="true">// also arrayDay(...), listDay(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">month</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>              <span class="token comment"
                                                                                  spellcheck="true">// also arrayMonth(...), listMonth(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">monthName</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>          <span class="token comment" spellcheck="true">// also arrayMonthName(...), listMonthName(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">monthNameShort</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>     <span class="token comment" spellcheck="true">// also arrayMonthNameShort(...), listMonthNameShort(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">year</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>               <span class="token comment"
                                                                                   spellcheck="true">// also arrayYear(...), listYear(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">dayOfWeek</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>          <span class="token comment" spellcheck="true">// also arrayDayOfWeek(...), listDayOfWeek(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">dayOfWeekName</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>      <span class="token comment" spellcheck="true">// also arrayDayOfWeekName(...), listDayOfWeekName(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">dayOfWeekNameShort</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span> <span class="token comment" spellcheck="true">// also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">hour</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>               <span class="token comment"
                                                                                   spellcheck="true">// also arrayHour(...), listHour(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">minute</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>             <span class="token comment"
                                                                                 spellcheck="true">// also arrayMinute(...), listMinute(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">second</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>             <span class="token comment"
                                                                                 spellcheck="true">// also arraySecond(...), listSecond(...), etc.</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">millisecond</span><span
                            class="token punctuation">(</span>date<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>        <span class="token comment" spellcheck="true">// also arrayMillisecond(...), listMillisecond(...), etc.</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Create calendar (java.util.Calendar) objects from its components
 */</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">create</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">create</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">create</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span class="token punctuation">,</span>second<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">create</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span class="token punctuation">,</span>second<span
                            class="token punctuation">,</span>millisecond<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">createForTimeZone</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>timeZone<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">createForTimeZone</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span
                            class="token punctuation">,</span>timeZone<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">createForTimeZone</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span class="token punctuation">,</span>second<span
                            class="token punctuation">,</span>timeZone<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">createForTimeZone</span><span
                            class="token punctuation">(</span>year<span class="token punctuation">,</span>month<span
                            class="token punctuation">,</span>day<span class="token punctuation">,</span>hour<span
                            class="token punctuation">,</span>minute<span class="token punctuation">,</span>second<span
                            class="token punctuation">,</span>millisecond<span class="token punctuation">,</span>timeZone<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Create a calendar (java.util.Calendar) object for the current date and time
 */</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">createNow</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">createNowForTimeZone</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Create a calendar (java.util.Calendar) object for the current date (time set to 00:00)
 */</span>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">createToday</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#calendars<span class="token punctuation">.</span><span class="token function">createTodayForTimeZone</span><span
                            class="token punctuation">(</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="numbers">
                <h3><font><font>数字</font></font></h3>
                <ul>
                    <li><strong><font><font>#numbers</font></font></strong><font><font>：数字对象的实用程序方法：</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Numbers
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * ==========================
 * Formatting integer numbers
 * ==========================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Set minimum integer digits.
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">formatInteger</span><span
                            class="token punctuation">(</span>num<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">arrayFormatInteger</span><span
                            class="token punctuation">(</span>numArray<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">listFormatInteger</span><span
                            class="token punctuation">(</span>numList<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">setFormatInteger</span><span
                            class="token punctuation">(</span>numSet<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Set minimum integer digits and thousands separator:
 * 'POINT', 'COMMA', 'WHITESPACE', 'NONE' or 'DEFAULT' (by locale).
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">formatInteger</span><span
                            class="token punctuation">(</span>num<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token string">'POINT'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">arrayFormatInteger</span><span
                            class="token punctuation">(</span>numArray<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token string">'POINT'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">listFormatInteger</span><span
                            class="token punctuation">(</span>numList<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token string">'POINT'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">setFormatInteger</span><span
                            class="token punctuation">(</span>numSet<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token string">'POINT'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * ==========================
 * Formatting decimal numbers
 * ==========================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Set minimum integer digits and (exact) decimal digits.
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">formatDecimal</span><span
                            class="token punctuation">(</span>num<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">arrayFormatDecimal</span><span
                            class="token punctuation">(</span>numArray<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">listFormatDecimal</span><span
                            class="token punctuation">(</span>numList<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">setFormatDecimal</span><span
                            class="token punctuation">(</span>numSet<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Set minimum integer digits and (exact) decimal digits, and also decimal separator.
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">formatDecimal</span><span
                            class="token punctuation">(</span>num<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">,</span><span
                            class="token string">'COMMA'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">arrayFormatDecimal</span><span
                            class="token punctuation">(</span>numArray<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">,</span><span
                            class="token string">'COMMA'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">listFormatDecimal</span><span
                            class="token punctuation">(</span>numList<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">,</span><span
                            class="token string">'COMMA'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">setFormatDecimal</span><span
                            class="token punctuation">(</span>numSet<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">,</span><span
                            class="token string">'COMMA'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Set minimum integer digits and (exact) decimal digits, and also thousands and
 * decimal separator.
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">formatDecimal</span><span
                            class="token punctuation">(</span>num<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token string">'POINT'</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">,</span><span
                            class="token string">'COMMA'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">arrayFormatDecimal</span><span
                            class="token punctuation">(</span>numArray<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token string">'POINT'</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">,</span><span
                            class="token string">'COMMA'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">listFormatDecimal</span><span
                            class="token punctuation">(</span>numList<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token string">'POINT'</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">,</span><span
                            class="token string">'COMMA'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">setFormatDecimal</span><span
                            class="token punctuation">(</span>numSet<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token string">'POINT'</span><span class="token punctuation">,</span><span
                            class="token number">2</span><span class="token punctuation">,</span><span
                            class="token string">'COMMA'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * =====================
 * Formatting currencies
 * =====================
 */</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">formatCurrency</span><span
                            class="token punctuation">(</span>num<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">arrayFormatCurrency</span><span
                            class="token punctuation">(</span>numArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">listFormatCurrency</span><span
                            class="token punctuation">(</span>numList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">setFormatCurrency</span><span
                            class="token punctuation">(</span>numSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * ======================
 * Formatting percentages
 * ======================
 */</span><font></font>
<font></font>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">formatPercent</span><span
                            class="token punctuation">(</span>num<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">arrayFormatPercent</span><span
                            class="token punctuation">(</span>numArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">listFormatPercent</span><span
                            class="token punctuation">(</span>numList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">setFormatPercent</span><span
                            class="token punctuation">(</span>numSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Set minimum integer digits and (exact) decimal digits.
 */</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">formatPercent</span><span
                            class="token punctuation">(</span>num<span class="token punctuation">,</span> <span
                            class="token number">3</span><span class="token punctuation">,</span> <span
                            class="token number">2</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">arrayFormatPercent</span><span
                            class="token punctuation">(</span>numArray<span class="token punctuation">,</span> <span
                            class="token number">3</span><span class="token punctuation">,</span> <span
                            class="token number">2</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">listFormatPercent</span><span
                            class="token punctuation">(</span>numList<span class="token punctuation">,</span> <span
                            class="token number">3</span><span class="token punctuation">,</span> <span
                            class="token number">2</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">setFormatPercent</span><span
                            class="token punctuation">(</span>numSet<span class="token punctuation">,</span> <span
                            class="token number">3</span><span class="token punctuation">,</span> <span
                            class="token number">2</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * ===============
 * Utility methods
 * ===============
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Create a sequence (array) of integer numbers going
 * from x to y
 */</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">sequence</span><span
                            class="token punctuation">(</span>from<span class="token punctuation">,</span>to<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#numbers<span class="token punctuation">.</span><span class="token function">sequence</span><span
                            class="token punctuation">(</span>from<span class="token punctuation">,</span>to<span
                            class="token punctuation">,</span>step<span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="strings">
                <h3><font><font>弦</font></font></h3>
                <ul>
                    <li>
                        <strong><font><font>#strings</font></font></strong><font><font>：</font></font><code>String</code><font><font>对象的</font><font>实用程序方法</font><font>：</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Strings
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Null-safe toString()
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">toString</span><span
                            class="token punctuation">(</span>obj<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                           <span class="token comment"
                                                                                               spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check whether a String is empty (or null). Performs a trim() operation before check
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">isEmpty</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">arrayIsEmpty</span><span
                            class="token punctuation">(</span>nameArr<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">listIsEmpty</span><span
                            class="token punctuation">(</span>nameList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">setIsEmpty</span><span
                            class="token punctuation">(</span>nameSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Perform an 'isEmpty()' check on a string and return it if false, defaulting to
 * another specified string if true.
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">defaultString</span><span
                            class="token punctuation">(</span>text<span class="token punctuation">,</span><span
                            class="token keyword">default</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">arrayDefaultString</span><span
                            class="token punctuation">(</span>textArr<span class="token punctuation">,</span><span
                            class="token keyword">default</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">listDefaultString</span><span
                            class="token punctuation">(</span>textList<span class="token punctuation">,</span><span
                            class="token keyword">default</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">setDefaultString</span><span
                            class="token punctuation">(</span>textSet<span class="token punctuation">,</span><span
                            class="token keyword">default</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check whether a fragment is contained in a String
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">contains</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span><span
                            class="token string">'ez'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                     <span class="token comment"
                                                                                         spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">containsIgnoreCase</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span><span
                            class="token string">'ez'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>           <span class="token comment" spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check whether a String starts or ends with a fragment
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">startsWith</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span><span
                            class="token string">'Don'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                  <span class="token comment"
                                                                                      spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">endsWith</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span>endingFragment<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>           <span
                            class="token comment" spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Substring-related operations
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">indexOf</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span>frag<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>                      <span
                            class="token comment" spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">substring</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span><span
                            class="token number">3</span><span class="token punctuation">,</span><span
                            class="token number">5</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                     <span class="token comment"
                                                                                         spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">substringAfter</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span>prefix<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>             <span
                            class="token comment" spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">substringBefore</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span>suffix<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>            <span
                            class="token comment" spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">replace</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">,</span><span
                            class="token string">'las'</span><span class="token punctuation">,</span><span
                            class="token string">'ler'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>               <span class="token comment"
                                                                                   spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Append and prepend
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">prepend</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">,</span>prefix<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>                     <span
                            class="token comment" spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">append</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">,</span>suffix<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>                      <span
                            class="token comment" spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Change case
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">toUpperCase</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                       <span class="token comment"
                                                                                           spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span
                            class="token punctuation">(</span>name<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                       <span class="token comment"
                                                                                           spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Split and join
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">arrayJoin</span><span
                            class="token punctuation">(</span>namesArray<span class="token punctuation">,</span><span
                            class="token string">','</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">listJoin</span><span
                            class="token punctuation">(</span>namesList<span class="token punctuation">,</span><span
                            class="token string">','</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">setJoin</span><span
                            class="token punctuation">(</span>namesSet<span class="token punctuation">,</span><span
                            class="token string">','</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">arraySplit</span><span
                            class="token punctuation">(</span>namesStr<span class="token punctuation">,</span><span
                            class="token string">','</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                <span class="token comment"
                                                                                    spellcheck="true">// returns String[]</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">listSplit</span><span
                            class="token punctuation">(</span>namesStr<span class="token punctuation">,</span><span
                            class="token string">','</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                 <span class="token comment"
                                                                                     spellcheck="true">// returns List&lt;String&gt;</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">setSplit</span><span
                            class="token punctuation">(</span>namesStr<span class="token punctuation">,</span><span
                            class="token string">','</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                  <span class="token comment"
                                                                                      spellcheck="true">// returns Set&lt;String&gt;</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Trim
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">trim</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                               <span class="token comment"
                                                                                                   spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Compute length
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">length</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                             <span class="token comment"
                                                                                                 spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Abbreviate text making it have a maximum size of n. If text is bigger, it
 * will be clipped and finished in "..."
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">abbreviate</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">,</span><span
                            class="token number">10</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                      <span class="token comment"
                                                                                          spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Convert the first character to upper-case (and vice-versa)
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">capitalize</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                         <span class="token comment"
                                                                                             spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">unCapitalize</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                       <span class="token comment"
                                                                                           spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Convert the first character of every word to upper-case
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">capitalizeWords</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                    <span class="token comment"
                                                                                        spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">capitalizeWords</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">,</span>delimiters<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>         <span
                            class="token comment" spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Escape the string
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">escapeXml</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                          <span class="token comment"
                                                                                              spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">escapeJava</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                         <span class="token comment"
                                                                                             spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">escapeJavaScript</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                   <span class="token comment"
                                                                                       spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">unescapeJava</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                       <span class="token comment"
                                                                                           spellcheck="true">// also array*, list* and set*</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">unescapeJavaScript</span><span
                            class="token punctuation">(</span>str<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>                 <span class="token comment"
                                                                                     spellcheck="true">// also array*, list* and set*</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Null-safe comparison and concatenation
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">equals</span><span
                            class="token punctuation">(</span>first<span class="token punctuation">,</span> second<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">equalsIgnoreCase</span><span
                            class="token punctuation">(</span>first<span class="token punctuation">,</span> second<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">concat</span><span
                            class="token punctuation">(</span>values<span class="token punctuation">.</span><span
                            class="token punctuation">.</span><span class="token punctuation">.</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">concatReplaceNulls</span><span
                            class="token punctuation">(</span>nullValue<span
                            class="token punctuation">,</span> values<span class="token punctuation">.</span><span
                            class="token punctuation">.</span><span class="token punctuation">.</span><span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Random
 */</span>
$<span class="token punctuation">{</span>#strings<span class="token punctuation">.</span><span class="token function">randomAlphanumeric</span><span
                            class="token punctuation">(</span>count<span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="objects">
                <h3><font><font>对象</font></font></h3>
                <ul>
                    <li><strong><font><font>#objects</font></font></strong><font><font>：一般对象的实用程序方法</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Objects
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Return obj if it is not null, and default otherwise
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#objects<span class="token punctuation">.</span><span class="token function">nullSafe</span><span
                            class="token punctuation">(</span>obj<span class="token punctuation">,</span><span
                            class="token keyword">default</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#objects<span class="token punctuation">.</span><span class="token function">arrayNullSafe</span><span
                            class="token punctuation">(</span>objArray<span class="token punctuation">,</span><span
                            class="token keyword">default</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#objects<span class="token punctuation">.</span><span class="token function">listNullSafe</span><span
                            class="token punctuation">(</span>objList<span class="token punctuation">,</span><span
                            class="token keyword">default</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#objects<span class="token punctuation">.</span><span class="token function">setNullSafe</span><span
                            class="token punctuation">(</span>objSet<span class="token punctuation">,</span><span
                            class="token keyword">default</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="booleans">
                <h3><font><font>布尔值</font></font></h3>
                <ul>
                    <li><strong><font><font>#bools</font></font></strong><font><font>：布尔评估的实用程序方法</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Bools
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Evaluate a condition in the same way that it would be evaluated in a th:if tag
 * (see conditional evaluation chapter afterwards).
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">isTrue</span><span
                            class="token punctuation">(</span>obj<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">arrayIsTrue</span><span
                            class="token punctuation">(</span>objArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">listIsTrue</span><span
                            class="token punctuation">(</span>objList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">setIsTrue</span><span
                            class="token punctuation">(</span>objSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Evaluate with negation
 * Also works with arrays, lists or sets
 */</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">isFalse</span><span
                            class="token punctuation">(</span>cond<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">arrayIsFalse</span><span
                            class="token punctuation">(</span>condArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">listIsFalse</span><span
                            class="token punctuation">(</span>condList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">setIsFalse</span><span
                            class="token punctuation">(</span>condSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Evaluate and apply AND operator
 * Receive an array, a list or a set as parameter
 */</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">arrayAnd</span><span
                            class="token punctuation">(</span>condArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">listAnd</span><span
                            class="token punctuation">(</span>condList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">setAnd</span><span
                            class="token punctuation">(</span>condSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Evaluate and apply OR operator
 * Receive an array, a list or a set as parameter
 */</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">arrayOr</span><span
                            class="token punctuation">(</span>condArray<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">listOr</span><span
                            class="token punctuation">(</span>condList<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#bools<span class="token punctuation">.</span><span class="token function">setOr</span><span
                            class="token punctuation">(</span>condSet<span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="arrays">
                <h3><font><font>数组</font></font></h3>
                <ul>
                    <li><strong><font><font>#arrays</font></font></strong><font><font>：数组的实用方法</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Arrays
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Converts to array, trying to infer array component class.
 * Note that if resulting array is empty, or if the elements
 * of the target object are not all of the same class,
 * this method will return Object[].
 */</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">toArray</span><span
                            class="token punctuation">(</span>object<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Convert to arrays of the specified component class.
 */</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">toStringArray</span><span
                            class="token punctuation">(</span>object<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">toIntegerArray</span><span
                            class="token punctuation">(</span>object<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">toLongArray</span><span
                            class="token punctuation">(</span>object<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">toDoubleArray</span><span
                            class="token punctuation">(</span>object<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">toFloatArray</span><span
                            class="token punctuation">(</span>object<span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">toBooleanArray</span><span
                            class="token punctuation">(</span>object<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Compute length
 */</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">length</span><span
                            class="token punctuation">(</span>array<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check whether array is empty
 */</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">isEmpty</span><span
                            class="token punctuation">(</span>array<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check if element or elements are contained in array
 */</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">contains</span><span
                            class="token punctuation">(</span>array<span class="token punctuation">,</span> element<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#arrays<span class="token punctuation">.</span><span class="token function">containsAll</span><span
                            class="token punctuation">(</span>array<span
                            class="token punctuation">,</span> elements<span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="lists">
                <h3><font><font>列表</font></font></h3>
                <ul>
                    <li><strong><font><font>#lists</font></font></strong><font><font>：列表的实用程序方法</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Lists
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Converts to list
 */</span>
$<span class="token punctuation">{</span>#lists<span class="token punctuation">.</span><span class="token function">toList</span><span
                            class="token punctuation">(</span>object<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Compute size
 */</span>
$<span class="token punctuation">{</span>#lists<span class="token punctuation">.</span><span
                            class="token function">size</span><span class="token punctuation">(</span>list<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check whether list is empty
 */</span>
$<span class="token punctuation">{</span>#lists<span class="token punctuation">.</span><span class="token function">isEmpty</span><span
                            class="token punctuation">(</span>list<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check if element or elements are contained in list
 */</span>
$<span class="token punctuation">{</span>#lists<span class="token punctuation">.</span><span class="token function">contains</span><span
                            class="token punctuation">(</span>list<span class="token punctuation">,</span> element<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#lists<span class="token punctuation">.</span><span class="token function">containsAll</span><span
                            class="token punctuation">(</span>list<span class="token punctuation">,</span> elements<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Sort a copy of the given list. The members of the list must implement
 * comparable or you must define a comparator.
 */</span>
$<span class="token punctuation">{</span>#lists<span class="token punctuation">.</span><span
                            class="token function">sort</span><span class="token punctuation">(</span>list<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#lists<span class="token punctuation">.</span><span
                            class="token function">sort</span><span class="token punctuation">(</span>list<span
                            class="token punctuation">,</span> comparator<span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="sets">
                <h3><font><font>集合</font></font></h3>
                <ul>
                    <li><strong><font><font>#sets</font></font></strong><font><font>：集合的实用程序方法</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Sets
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Converts to set
 */</span>
$<span class="token punctuation">{</span>#sets<span class="token punctuation">.</span><span
                            class="token function">toSet</span><span class="token punctuation">(</span>object<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Compute size
 */</span>
$<span class="token punctuation">{</span>#sets<span class="token punctuation">.</span><span
                            class="token function">size</span><span class="token punctuation">(</span>set<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check whether set is empty
 */</span>
$<span class="token punctuation">{</span>#sets<span class="token punctuation">.</span><span class="token function">isEmpty</span><span
                            class="token punctuation">(</span>set<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check if element or elements are contained in set
 */</span>
$<span class="token punctuation">{</span>#sets<span class="token punctuation">.</span><span class="token function">contains</span><span
                            class="token punctuation">(</span>set<span class="token punctuation">,</span> element<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#sets<span class="token punctuation">.</span><span class="token function">containsAll</span><span
                            class="token punctuation">(</span>set<span class="token punctuation">,</span> elements<span
                            class="token punctuation">)</span><span class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="maps">
                <h3><font><font>地图</font></font></h3>
                <ul>
                    <li><strong><font><font>#maps</font></font></strong><font><font>：地图的实用方法</font></font></li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Maps
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Compute size
 */</span>
$<span class="token punctuation">{</span>#maps<span class="token punctuation">.</span><span
                            class="token function">size</span><span class="token punctuation">(</span>map<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check whether map is empty
 */</span>
$<span class="token punctuation">{</span>#maps<span class="token punctuation">.</span><span class="token function">isEmpty</span><span
                            class="token punctuation">(</span>map<span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Check if key/s or value/s are contained in maps
 */</span>
$<span class="token punctuation">{</span>#maps<span class="token punctuation">.</span><span class="token function">containsKey</span><span
                            class="token punctuation">(</span>map<span class="token punctuation">,</span> key<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#maps<span class="token punctuation">.</span><span class="token function">containsAllKeys</span><span
                            class="token punctuation">(</span>map<span class="token punctuation">,</span> keys<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#maps<span class="token punctuation">.</span><span class="token function">containsValue</span><span
                            class="token punctuation">(</span>map<span class="token punctuation">,</span> value<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#maps<span class="token punctuation">.</span><span class="token function">containsAllValues</span><span
                            class="token punctuation">(</span>map<span class="token punctuation">,</span> value<span
                            class="token punctuation">)</span><span class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="aggregates">
                <h3><font><font>聚集</font></font></h3>
                <ul>
                    <li>
                        <strong><font><font>#aggregates</font></font></strong><font><font>：在数组或集合上创建聚合的实用方法</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Aggregates
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Compute sum. Returns null if array or collection is empty
 */</span>
$<span class="token punctuation">{</span>#aggregates<span class="token punctuation">.</span><span
                            class="token function">sum</span><span class="token punctuation">(</span>array<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#aggregates<span class="token punctuation">.</span><span
                            class="token function">sum</span><span class="token punctuation">(</span>collection<span
                            class="token punctuation">)</span><span class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Compute average. Returns null if array or collection is empty
 */</span>
$<span class="token punctuation">{</span>#aggregates<span class="token punctuation">.</span><span
                            class="token function">avg</span><span class="token punctuation">(</span>array<span
                            class="token punctuation">)</span><span class="token punctuation">}</span>
$<span class="token punctuation">{</span>#aggregates<span class="token punctuation">.</span><span
                            class="token function">avg</span><span class="token punctuation">(</span>collection<span
                            class="token punctuation">)</span><span class="token punctuation">}</span></code></pre>
            </section>
            <section class="level3" id="ids">
                <h3><font><font>ID</font></font></h3>
                <ul>
                    <li>
                        <strong><font><font>#ids</font></font></strong><font><font>：处理</font></font><code>id</code><font><font>可能重复的</font><strong><font>属性的</font></strong><font>实用方法</font><font>（例如，作为迭代的结果）。</font></font>
                    </li>
                </ul>
                <pre class="  language-java"><code class="  language-java"><span class="token comment"
                                                                                 spellcheck="true">/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.expression.Ids
 * ======================================================================
 */</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Normally used in th:id attributes, for appending a counter to the id attribute value
 * so that it remains unique even when involved in an iteration process.
 */</span>
$<span class="token punctuation">{</span>#ids<span class="token punctuation">.</span><span
                            class="token function">seq</span><span class="token punctuation">(</span><span
                            class="token string">'someId'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span><font></font>
<font></font>
<span class="token comment" spellcheck="true">/*
 * Normally used in th:for attributes in &lt;label&gt; tags, so that these labels can refer to Ids
 * generated by means if the #ids.seq(...) function.
 *
 * Depending on whether the &lt;label&gt; goes before or after the element with the #ids.seq(...)
 * function, the "next" (label goes before "seq") or the "prev" function (label goes after
 * "seq") function should be called.
 */</span>
$<span class="token punctuation">{</span>#ids<span class="token punctuation">.</span><span
                            class="token function">next</span><span class="token punctuation">(</span><span
                            class="token string">'someId'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span>
$<span class="token punctuation">{</span>#ids<span class="token punctuation">.</span><span
                            class="token function">prev</span><span class="token punctuation">(</span><span
                            class="token string">'someId'</span><span class="token punctuation">)</span><span
                            class="token punctuation">}</span></code></pre>
            </section>
        </section>
        <section class="level1" id="appendix-c-markup-selector-syntax">
            <h1><font><font>20附录C：标记选择器语法</font></font></h1>
            <p><font><font>Thymeleaf的标记选择器直接从Thymeleaf的解析库中借用：</font></font><a href="http://attoparser.org"><font><font>AttoParser</font></font></a><font><font>。</font></font>
            </p>
            <p>
                <font><font>该选择器的语法与XPath，CSS和jQuery中的选择器具有很大的相似性，这使得它们可以方便大多数用户使用。</font><font>您可以在AttoParser文档中查看完整的语法</font></font><a
                    href="http://www.attoparser.org/apidocs/attoparser/2.0.0.RELEASE/org/attoparser/select/package-summary.html"><font><font>参考</font></font></a><font><font>。</font></font>
            </p>
            <p>
                <font><font>例如，以下选择器将</font><font>在标记中的每个位置中</font><font>选择每一个</font></font><code>&lt;div&gt;</code><font><font>类别</font></font><code>content</code><font><font>（请注意，这不是简单的，可以阅读以了解为什么）：</font></font>
            </p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>insert</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>mytemplate :: //div[@class<span class="token punctuation">=</span><span
                    class="token punctuation">'</span>content<span class="token punctuation">'</span>]<span
                    class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                    class="token tag"><span class="token tag"><span
                    class="token punctuation">&lt;/</span>div</span><span
                    class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>基本语法包括：</font></font></p>
            <ul>
                <li><p><code>/x</code><font><font> 表示当前节点的直接子节点，名称为x。</font></font></p></li>
                <li><p><code>//x</code><font><font> 指当前节点的名字为x的任何深度的孩子。</font></font></p></li>
                <li><p><code>x[@z="v"]</code><font><font> 表示名称为x的元素和名为z的属性，值为“v”。</font></font></p></li>
                <li><p><code>x[@z1="v1" and @z2="v2"]</code><font><font> 表示分别具有名称x和属性z1和z2的值为“v1”和“v2”的元素。</font></font>
                </p></li>
                <li><p><code>x[i]</code><font><font> 意思是在其兄弟姐妹中名字x位于第i位的元素。</font></font></p></li>
                <li><p><code>x[@z="v"][i]</code><font><font> 表示名称为x的属性，属性z的值为“v”，并且位于同样匹配此条件的兄弟姐妹之间的数字i中。</font></font>
                </p></li>
            </ul>
            <p><font><font>但是也可以使用更简洁的语法：</font></font></p>
            <ul>
                <li><p>
                    <code>x</code><font><font>是完全等效于</font></font><code>//x</code><font><font>（搜索与名字或参考一个元件</font></font><code>x</code><font><font>在任何深度级别，一个</font></font><em><font><font>参考</font></font></em><font><font>是一个</font></font><code>th:ref</code><font><font>或一个</font></font><code>th:fragment</code><font><font>属性）。</font></font>
                </p></li>
                <li><p>
                    <font><font>只要包含参数的规范，选择器也不允许使用元素名称/引用。</font><font>所以</font></font><code>[@class='oneclass']</code><font><font>是一个有效的选择器，可以查找具有值属性的任何元素（标签）</font></font><code>"oneclass"</code><font><font>。</font></font>
                </p></li>
            </ul>
            <p><font><font>高级属性选择功能：</font></font></p>
            <ul>
                <li><p>
                    <font><font>除了</font></font><code>=</code><font><font>（相等）外，其他比较运算符也是有效的：（</font></font><code>!=</code><font><font>不等于），</font></font><code>^=</code><font><font>（以开始）和</font></font><code>$=</code><font><font>（以...结尾）。</font><font>例如：</font></font><code>x[@class^='section']</code><font><font>表示具有名称</font></font><code>x</code><font><font>和属性</font></font><code>class</code><font><font>开始</font><font>的值的元素</font></font><code>section</code><font><font>。</font></font>
                </p></li>
                <li><p>
                    <font><font>属性可以从</font></font><code>@</code><font><font>（XPath-style）和without（jQuery-style）</font><font>开始指定</font><font>。</font><font>所以</font></font><code>x[z='v']</code><font><font>相当于</font></font><code>x[@z='v']</code><font><font>。</font></font>
                </p></li>
                <li><p>
                    <font><font>多属性修饰符可以使用</font></font><code>and</code><font><font>（XPath样式）和链接多个修饰符（jQuery样式）进行连接。</font><font>所以</font></font><code>x[@z1='v1'
                    and @z2='v2']</code><font><font>实际上等同于</font></font><code>x[@z1='v1'][@z2='v2']</code><font><font>（也是</font></font><code>x[z1='v1'][z2='v2']</code><font><font>）。</font></font>
                </p></li>
            </ul>
            <p><font><font>直接的</font></font><em><font><font>jQuery样</font></font></em><font><font>选择器：</font></font></p>
            <ul>
                <li><p>
                    <code>x.oneclass</code><font><font>相当于</font></font><code>x[class='oneclass']</code><font><font>。</font></font>
                </p></li>
                <li><p>
                    <code>.oneclass</code><font><font>相当于</font></font><code>[class='oneclass']</code><font><font>。</font></font>
                </p></li>
                <li><p>
                    <code>x#oneid</code><font><font>相当于</font></font><code>x[id='oneid']</code><font><font>。</font></font>
                </p></li>
                <li><p>
                    <code>#oneid</code><font><font>相当于</font></font><code>[id='oneid']</code><font><font>。</font></font>
                </p></li>
                <li><p>
                    <code>x%oneref</code><font><font>指</font></font><code>&lt;x&gt;</code><font><font>具有</font></font><code>th:ref="oneref"</code><font><font>或</font></font><code>th:fragment="oneref"</code><font><font>属性的</font><font>标签</font><font>。</font></font>
                </p></li>
                <li><p><code>%oneref</code><font><font>指具有</font></font><code>th:ref="oneref"</code><font><font>或</font></font><code>th:fragment="oneref"</code><font><font>属性的</font><font>任何标签</font><font>。</font><font>注意，这实际上等同于简单地</font></font><code>oneref</code><font><font>因为可以使用引用而不是元素名称。</font></font>
                </p></li>
                <li><p>
                    <font><font>直接选择器和属性选择器可以混合使用：</font></font><code>a.external[@href^='https']</code><font><font>。</font></font>
                </p></li>
            </ul>
            <p><font><font>所以上面的Markup Selector表达式：</font></font></p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>insert</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>mytemplate :: //div[@class<span class="token punctuation">=</span><span
                    class="token punctuation">'</span>content<span class="token punctuation">'</span>]<span
                    class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                    class="token tag"><span class="token tag"><span
                    class="token punctuation">&lt;/</span>div</span><span
                    class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>可写为：</font></font></p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>insert</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>mytemplate :: div.content<span class="token punctuation">"</span></span><span
                    class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span
                    class="token punctuation">&lt;/</span>div</span><span
                    class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>检查一个不同的例子，这个：</font></font></p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>replace</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>mytemplate :: myfrag<span
                    class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                    class="token tag"><span class="token tag"><span
                    class="token punctuation">&lt;/</span>div</span><span
                    class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>将寻找</font></font><code>th:fragment="myfrag"</code><font><font>片段签名（或</font></font><code>th:ref</code><font><font>引用）。</font><font>但是，</font></font><code>myfrag</code><font><font>如果它们存在，那么它</font><font>也会寻找带有名称的标签</font><font>（在HTML中它们不是）。</font><font>注意与...的区别：</font></font>
            </p>
            <pre class="  language-html"><code class="  language-html"><span class="token tag"><span
                    class="token tag"><span class="token punctuation">&lt;</span>div</span> <span
                    class="token attr-name"><span class="token namespace">th:</span>replace</span><span
                    class="token attr-value"><span class="token punctuation">=</span><span
                    class="token punctuation">"</span>mytemplate :: .myfrag<span
                    class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>...<span
                    class="token tag"><span class="token tag"><span
                    class="token punctuation">&lt;/</span>div</span><span
                    class="token punctuation">&gt;</span></span></code></pre>
            <p><font><font>...它将实际寻找任何元素</font></font><code>class="myfrag"</code><font><font>，而不关心</font></font><code>th:fragment</code><font><font>签名（或</font></font><code>th:ref</code><font><font>引用）。</font></font>
            </p>
            <section class="level3" id="multivalued-class-matching">
                <h3><font><font>多值类匹配</font></font></h3>
                <p><font><font>标记选择器将类属性理解为多</font></font><strong><font><font>值</font></font></strong><font><font>，因此即使该元素具有多个类值，也允许在该属性上应用选择器。</font></font>
                </p>
                <p><font><font>例如，</font></font><code>div.two</code><font><font>将匹配</font></font><code>&lt;div
                    class="one two three" /&gt;</code></p>
            </section>
        </section>
    </div>

</div>
<div class="goog-tooltip skiptranslate" dir="ltr" id="goog-gt-tt"
     style="visibility: hidden; left: 140px; top: 305px; display: none;">
    <div style="padding: 8px;">
        <div>
            <div class="logo"><img alt="Google 翻译"
                                   height="20"
                                   src="https://www.gstatic.com/images/branding/product/1x/translate_24dp.png"
                                   width="20"></div>
        </div>
    </div>
    <div class="top" style="padding: 8px; float: left; width: 100%;"><h1 class="title gray">原文</h1></div>
    <div class="middle" style="padding: 8px;">
        <div class="original-text">There are different types of URLs:</div>
    </div>
    <div class="bottom" style="padding: 8px;">
        <div class="activity-links"><span class="activity-link">提供更好的翻译建议</span><span class="activity-link"></span>
        </div>
        <div class="started-activity-container">
            <hr style="color: #CCC; background-color: #CCC; height: 1px; border: none;">
            <div class="activity-root"></div>
        </div>
    </div>
    <div class="status-message" style="display: none; opacity: 0;"></div>
</div>


<div class="goog-te-spinner-pos">
    <div class="goog-te-spinner-animation">
        <svg class="goog-te-spinner" height="96px" viewBox="0 0 66 66" width="96px" xmlns="http://www.w3.org/2000/svg">
            <circle class="goog-te-spinner-path" cx="33" cy="33" fill="none" r="30" stroke-linecap="round"
                    stroke-width="6"></circle>
        </svg>
    </div>
</div>
<div draggable="true" id="yddWrapper" style="left: 841px; top: 316px;" tag-info="这是有道词典 “Chrome 划词扩展 V3” 插入的节点"></div>
<template id="yodaoDictPanel" tag-info="这是有道词典 “Chrome 划词扩展 V3” 插入的节点">
    <style> @import "chrome-extension://chgkpfgnhlojjpjchjcbpbgmdnmfmmil/youdao-crx.css}"; </style>
    <div id="ydd-content"></div>
</template>
</body>
</html>